# HG changeset patch # User Thierry Florac # Date 1538059265 -7200 # Node ID 606d951d75914d541d32fdfb3ed69251914e5dca # Parent 34a88f2fec727bf3d469e2396ba79400e1974225 Updated tags content provider diff -r 34a88f2fec72 -r 606d951d7591 src/pyams_default_theme/viewlet/tag/__init__.py --- a/src/pyams_default_theme/viewlet/tag/__init__.py Thu Sep 27 16:28:29 2018 +0200 +++ b/src/pyams_default_theme/viewlet/tag/__init__.py Thu Sep 27 16:41:05 2018 +0200 @@ -10,28 +10,35 @@ # FOR A PARTICULAR PURPOSE. # + __docformat__ = 'restructuredtext' - -# import standard library - -# import interfaces -from pyams_content.component.theme import ITagsTarget, ITagsInfo, ITagsManager -from pyams_skin.layer import IPyAMSLayer - -# import packages -from pyams_sequence.reference import get_reference_target -from pyams_template.template import template_config -from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider from pyramid.decorator import reify from zope.interface import Interface +from pyams_content.component.theme import ITagsInfo, ITagsManager +from pyams_sequence.reference import get_reference_target +from pyams_skin.layer import IPyAMSLayer, IPyAMSUserLayer +from pyams_template.template import template_config +from pyams_viewlet.viewlet import ViewContentProvider, contentprovider_config -@contentprovider_config(name='pyams.tags', context=ITagsTarget, layer=IPyAMSLayer, view=Interface) + +@contentprovider_config(name='pyams.tags', layer=IPyAMSUserLayer, view=Interface) @template_config(template='templates/tags.pt', layer=IPyAMSLayer) class TagsContentProvider(ViewContentProvider): """Tags content provider""" + tags_info = None + + def update(self): + super(TagsContentProvider, self).update() + self.tags_info = ITagsInfo(self.context, None) + + def render(self): + if self.tags_info is None: + return '' + return super(TagsContentProvider, self).render() + @reify def search_target(self): manager = ITagsManager(self.request.root, None) @@ -40,5 +47,5 @@ @property def tags(self): - tags = ITagsInfo(self.context).tags or () + tags = self.tags_info.tags or () yield from sorted(tags, key=lambda x: (x.order or 999, x.alt or x.label))