[PATCH 2 of 2 skos] Don't crash if there are no concepts to display

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 30 18:39:13 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490875901 -7200
#      Thu Mar 30 14:11:41 2017 +0200
# Node ID 09ea2bc20ce839e0b4286be824c2aed42f8ba8cb
# Parent  5982de98291d730dee6497c4fbbb8a4e951ca23a
Don't crash if there are no concepts to display

by first testing it's not an empty rset.

diff --git a/views/__init__.py b/views/__init__.py
--- a/views/__init__.py
+++ b/views/__init__.py
@@ -154,15 +154,17 @@ class ConceptSchemeConceptsTab(tabs.Tabs
             self.w(tags.a(self._cw._('import concepts'),
                           href=entity.absolute_url(vid='skos.scheme.import'),
                           klass='btn btn-success pull-right'))
             self.w(tags.div(klass='clearfix'))
         rset = entity.top_concepts_rset
-        if len(rset) < self._cw.property_value('navigation.page-size'):
-            treeid = 'skos_tree_%s' % entity.eid
-            self._cw.view('treeview', rset=rset, treeid=treeid, initial_thru_ajax=True, w=self.w)
-        elif rset:
-            self._cw.view('paginated-list', rset=rset, w=self.w)
+        if rset:
+            if len(rset) < self._cw.property_value('navigation.page-size'):
+                treeid = 'skos_tree_%s' % entity.eid
+                self._cw.view('treeview', rset=rset, treeid=treeid,
+                              initial_thru_ajax=True, w=self.w)
+            else:
+                self._cw.view('paginated-list', rset=rset, w=self.w)
 
 
 class ConceptPrimaryView(tabs.TabbedPrimaryView):
     __select__ = is_instance('Concept')
     tabs = ['main_tab', _('skos_sub_concepts_tab')]
@@ -174,12 +176,13 @@ class ConceptConceptsTab(tabs.TabsMixin,
     __select__ = (is_instance('Concept') &
                   has_related_entities('narrower_concept'))
 
     def entity_call(self, entity):
         rset = entity.related('narrower_concept')
-        treeid = 'skos_tree_%s' % entity.eid
-        self._cw.view('treeview', rset=rset, treeid=treeid, initial_thru_ajax=True, w=self.w)
+        if rset:
+            treeid = 'skos_tree_%s' % entity.eid
+            self._cw.view('treeview', rset=rset, treeid=treeid, initial_thru_ajax=True, w=self.w)
 
 
 class ConceptLabelsComponent(component.EntityCtxComponent):
     """display concept labels in a table"""
     __regid__ = 'skos.concept.labels'


More information about the saem-devel mailing list