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

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Mar 21 14:19:38 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 9c56fe5297e7a9afe7dcf917fb325ccd6f5356a0
# Parent  1f85b2c5209177f01335515b4900edd8ffef0b4d
[eac] Display chronological/hierarchical relations as list as well as timeline/graph

timeline / graph have different problems:

* timeline isn't able to display entities which have no date, while you can
  still create a chronological relation to them, making them unreachable

* graph isn't suited to display description and other details,

* both aren't suited to display controls (edit / delete).

So we decided to have a list view consistently for chronological and
hierarchical relations.

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):
+    """Display relations as list with edit links."""
+    __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.subject, entity.object):
+            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,37 +651,34 @@ 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'))
-
-    @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')
 
 
-pvs.tag_object_of(('*', 'chronological_predecessor', 'AuthorityRecord'), 'hidden')
-pvs.tag_object_of(('*', 'chronological_successor', 'AuthorityRecord'), 'hidden')
+class RelationRelatedView(EntityView):
+    __regid__ = 'saem.authorityrecord.relation.related'
+    __select__ = match_kwargs('from_rtype', 'to_rtype', 'title')
+
+    def entity_call(self, entity, from_rtype, to_rtype, title):
+        rset = self._cw.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:
+            self.w(tags.h3(title))
+            self._cw.view('list', rset=rset, w=self.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.
@@ -679,10 +699,19 @@ 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})
 
+        self._cw.view('saem.authorityrecord.relation.related', entity=entity, w=self.w,
+                      from_rtype='chronological_predecessor',
+                      to_rtype='chronological_successor',
+                      title=self._cw._('predecessors'))
+        self._cw.view('saem.authorityrecord.relation.related', entity=entity, w=self.w,
+                      from_rtype='chronological_successor',
+                      to_rtype='chronological_predecessor',
+                      title=self._cw._('successors'))
+
 
 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')
@@ -804,10 +833,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, '
@@ -836,8 +866,17 @@ 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>')
 
+        self._cw.view('saem.authorityrecord.relation.related', entity=entity, w=self.w,
+                      from_rtype='hierarchical_parent',
+                      to_rtype='hierarchical_child',
+                      title=self._cw._('parents'))
+        self._cw.view('saem.authorityrecord.relation.related', entity=entity, w=self.w,
+                      from_rtype='hierarchical_child',
+                      to_rtype='hierarchical_parent',
+                      title=self._cw._('children'))
+
 
 pvs.tag_object_of(('*', 'hierarchical_parent', 'AuthorityRecord'), 'hidden')
 pvs.tag_object_of(('*', 'hierarchical_child', 'AuthorityRecord'), 'hidden')


More information about the saem-devel mailing list