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

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Mar 31 10:10:32 CEST 2017



Le 31/03/2017 à 10:08, Denis Laxalde a écrit :
> Sylvain Thenault a écrit :
>> # 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)
>
> Could be written as:
>
> if not rset:
>   return
>
> thus eliminating the need to re-indent subsequent lines.
>
>>
>>  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)
>>
>>
>
> How can "rset = entity.related('narrower_concept')" be empty given the
> "has_related_entities('narrower_concept')" predicate?
>
right, missed the predicate. Will send a V2

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list