[PATCH 7 of 9 saem_ref] [eac] Display chronological/hierarchical relations as list as well as timeline/graph

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 16 17:38:22 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489674798 -3600
#      Thu Mar 16 15:33:18 2017 +0100
# Node ID 45ef4ef9f186e7bab3f93c7494dea1eef6277053
# Parent  0b28ac3950d4b14eefd3661819a50f357e5a106a
[eac] Display chronological/hierarchical relations as list as well as timeline/graph


Related to extranet #14591642

diff --git a/cubicweb_saem_ref/views/authorityrecord.py b/cubicweb_saem_ref/views/authorityrecord.py
--- a/cubicweb_saem_ref/views/authorityrecord.py
+++ b/cubicweb_saem_ref/views/authorityrecord.py
@@ -610,10 +610,33 @@ class AuthorityRecordRelationsTab(Subvie
 
 pvs.tag_object_of(('*', 'association_from', 'AuthorityRecord'), 'hidden')
 pvs.tag_object_of(('*', 'association_to', 'AuthorityRecord'), 'hidden')
 
 
+class RelationView(EntityView):
+    """Extended 'oneline' view for AssociationRelation"""
+    __regid__ = 'saem.authorityrecord.relation'
+    __select__ = (EntityView.__select__
+                  & is_instance('AssociationRelation',
+                                'ChronologicalRelation',
+                                'HierarchicalRelation')
+                  & match_kwargs('main_record'))
+
+    @editlinks(icon_info=True)
+    def entity_call(self, entity, main_record):
+        for other_record in (entity.left, entity.right):
+            if other_record != main_record:
+                self.w(other_record.view('outofcontext'))
+                break
+        if entity.start_date or entity.end_date:
+            self.w(tags.span(u' ({0}-{1})'.format(entity.printable_value('start_date'),
+                                                  entity.printable_value('end_date')),
+                             klass='text-muted'))
+        if entity.description:
+            self.w(tags.div(entity.printable_value('description')))
+
+
 class AuthorityRecordAssociationRelationView(EntityView):
     """View for association relations to be displayed in the context of an
     AuthorityRecord on either the `from` or `to` side of the relation.
     """
     __regid__ = 'saem.authorityrecord.association_relations'
@@ -628,38 +651,31 @@ class AuthorityRecordAssociationRelation
             'X description XD, X start_date XSD, X end_date XED, X association_to XAT) '
             'UNION (Any X,XD,XSD,XED,XAF,XAT WHERE X association_to XAT, XAT eid %(eid)s, '
             'X description XD, X start_date XSD, X end_date XED, X association_from XAF)',
             {'eid': entity.eid})
         self._cw.view('list', rset=rset, w=self.w,
-                      subvid='saem.associationrelation',
+                      subvid='saem.authorityrecord.relation',
                       main_record=entity,
                       __redirectpath=entity.rest_path())
 
 
-class AssociationRelationView(EntityView):
-    """Extended 'oneline' view for AssociationRelation"""
-    __regid__ = 'saem.authorityrecord.relation'
-    __select__ = (EntityView.__select__ &
-                  is_instance('AssociationRelation') & match_kwargs('main_record'))
+pvs.tag_object_of(('*', 'chronological_predecessor', 'AuthorityRecord'), 'hidden')
+pvs.tag_object_of(('*', 'chronological_successor', 'AuthorityRecord'), 'hidden')
 
 
-    @editlinks(icon_info=True)
-    def entity_call(self, entity, main_record):
-        for other_record in (entity.association_from[0], entity.association_to[0]):
-            if other_record != main_record:
-                self.w(other_record.view('outofcontext'))
-                break
-        if entity.start_date or entity.end_date:
-            self.w(tags.span(u' ({0}-{1})'.format(entity.printable_value('start_date'),
-                                                  entity.printable_value('end_date')),
-                             klass='text-muted'))
-        if entity.description:
-            self.w(tags.div(entity.printable_value('description')))
-
-
-pvs.tag_object_of(('*', 'chronological_predecessor', 'AuthorityRecord'), 'hidden')
-pvs.tag_object_of(('*', 'chronological_successor', 'AuthorityRecord'), 'hidden')
+def _display_related(entity, from_rtype, to_rtype, title, w):
+    req = entity._cw
+    rset = req.execute(
+        'Any X,XD,XSD,XED,XAF,XAT WHERE X {} XAF, XAF eid %(eid)s, '
+        'X description XD, X start_date XSD, X end_date XED, X {} XAT'
+        .format(from_rtype, to_rtype), {'eid': entity.eid})
+    if rset:
+        w(tags.h3(title))
+        req.view('list', rset=rset, w=w,
+                 subvid='saem.authorityrecord.relation',
+                 main_record=entity,
+                 __redirectpath=entity.rest_path())
 
 
 class ChronologicalRelationView(EntityView):
     """Timeline view with authority records involved in a ChronologicalRelation with this authority
     record entity.
@@ -680,10 +696,15 @@ class ChronologicalRelationView(EntityVi
                                 {'eid': entity.eid})
         json_url = self._cw.build_url('view', rql=entity.as_rset().printable_rql(),
                                       vid='saem.authorityrecord-timeline-json')
         self._cw.view('vtimeline', rset=rset, w=self.w, custom_settings={'source': json_url})
 
+        _display_related(entity, 'chronological_predecessor', 'chronological_successor',
+                         self._cw._('predecessors'), self.w)
+        _display_related(entity, 'chronological_successor', 'chronological_predecessor',
+                         self._cw._('successors'), self.w)
+
 
 class AuthorityRecordTimelineJsonView(EntityView):
     """JSON view for agent with chronological relations to be used with vtimeline view."""
     __regid__ = 'saem.authorityrecord-timeline-json'
     __select__ = is_instance('AuthorityRecord')
@@ -805,10 +826,11 @@ class AuthorityRecordGraphView(EntityVie
     __regid__ = 'saem.authorityrecord.hierarchical-links'
     title = _('HierarchicalRelation_plural')
 
     def entity_call(self, entity, **kwargs):
         self.w(tags.h2(self._cw._(self.title).lower()))
+
         self._cw.add_js(('jquery.js', 'jquery.jOrgChart.js'))
         self._cw.add_css('jquery.jOrgChart.css')
         hiera_list = u'<ul id="hierarchical_relations" style="display:none">'
         tags_closure = u'</ul>'
         rset_parents = self._cw.execute('Any P, PR WHERE PR hierarchical_child X, '
@@ -837,8 +859,13 @@ class AuthorityRecordGraphView(EntityVie
             self.w(u'<div class="other-parents icon-attention">')
             self.w(self._cw._('AuthorityRecord %s has several parents:') % entity.dc_title())
             self._cw.view('list', rset_parents, w=self.w)
             self.w(u'</div>')
 
+        _display_related(entity, 'hierarchical_parent', 'hierarchical_child',
+                         self._cw._('parents'), self.w)
+        _display_related(entity, 'hierarchical_child', 'hierarchical_parent',
+                         self._cw._('children'), self.w)
+
 
 pvs.tag_object_of(('*', 'hierarchical_parent', 'AuthorityRecord'), 'hidden')
 pvs.tag_object_of(('*', 'hierarchical_child', 'AuthorityRecord'), 'hidden')


More information about the saem-devel mailing list