[PATCH 5 of 7 saem_ref V2] [eac] Simplify graph generation

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Mar 21 10:50:09 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490089571 -3600
#      Tue Mar 21 10:46:11 2017 +0100
# Node ID 2b71ef323ecb049a6983b840327b91b858eaacb5
# Parent  e21c8d606253924623b0ed29d735ad0983755dcc
[eac] Simplify graph generation

now that relations are also displayed as 'standard' list which offers dates,
and description, we don't have to bother adding such information to the
hierarchical graph.

Related to #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
@@ -755,49 +755,17 @@ class AuthorityRecordTimelineJsonView(En
             if calendarable.stop:
                 date['endDate'] = ustrftime(calendarable.stop, '%Y,%m,%d')
         return date
 
 
-def _node(entity, rel=None):
-    req = entity._cw
-    if rel is not None:
-        url = entity.absolute_url()
-        descr = rel.printable_value('description', format='text/plain')
-        if descr:
-            descr_url_desc = descr
-            descr = cut(descr, 100)
-        else:
-            descr = req._('<no description specified>')
-            descr_url_desc = req._('view this relation')
-        descr_url = rel.absolute_url()
-        dates = []
-        if rel.start_date:
-            dates.append(rel.printable_value('start_date'))
-        if rel.end_date:
-            dates.append(rel.printable_value('end_date'))
-    else:
-        url = descr = descr_url = descr_url_desc = dates = u''
-    title = entity.dc_title()
+def _node(entity):
     return {
         'id': text_type(entity.eid),
-        'title': cut(title, 30),
-        'title_url': url,
-        'title_url_desc': title,
-        'descr': descr,
-        'descr_url': descr_url,
-        'descr_url_desc': descr_url_desc,
-        'dates': u' - '.join(dates),
+        'title': cut(entity.dc_title(), 30),
     }
 
 
-def _add_html_node_content(properties):
-    return (u'<p>%(title)s</p><p>%(descr)s</p><p class="dates">%(dates)s</p>' %
-            {'title': tags.a(properties['title'], href=properties['title_url'], klass=u'title'),
-             'descr': tags.a(properties['descr'], href=properties['descr_url']),
-             'dates': properties['dates']})
-
-
 class AuthorityRecordGraphView(EntityView):
     __select__ = EntityView.__select__ & (
         has_related_entities('hierarchical_parent', role='object') |
         has_related_entities('hierarchical_child', role='object'))
 
@@ -809,26 +777,25 @@ class AuthorityRecordGraphView(EntityVie
 
         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, '
+        rset_parents = self._cw.execute('Any P WHERE PR hierarchical_child X, '
                                         'PR hierarchical_parent P, X eid %(eid)s',
                                         {'eid': entity.eid})
         if rset_parents:
             parent = rset_parents.get_entity(0, 0)
-            parent_rel = rset_parents.get_entity(0, 1)
-            nprops = _node(parent, parent_rel)
-            hiera_list += u'<li>' + _add_html_node_content(nprops) + u'<ul>'
+            nprops = _node(parent)
+            hiera_list += u'<li>{}<ul>'.format(nprops['title'])
             tags_closure = u'</ul></li>' + tags_closure
         nprops = _node(entity)
-        hiera_list += u'<li class="main">' + _add_html_node_content(nprops) + u'<ul>'
+        hiera_list += u'<li class="main">{}<ul>'.format(nprops['title'])
         tags_closure = u'</ul></li>' + tags_closure
         for child_rel in entity.reverse_hierarchical_parent:
             for child in child_rel.hierarchical_child:
-                nprops = _node(child, child_rel)
-                hiera_list += u'<li>' + _add_html_node_content(nprops) + u'</li>'
+                nprops = _node(child)
+                hiera_list += u'<li></li>'.format(nprops['title'])
         hiera_list += tags_closure
         self.w(hiera_list)
         domid = make_uid()
         self._cw.add_onload(js.cw.jqNode('hierarchical_relations').jOrgChart(
             JSString('{chartElement: %s}' % js.cw.jqNode(domid))))


More information about the saem-devel mailing list