Updated tags content provider
authorThierry Florac <thierry.florac@onf.fr>
Thu, 27 Sep 2018 16:41:05 +0200
changeset 158 606d951d7591
parent 157 34a88f2fec72
child 159 38af361bdd7c
Updated tags content provider
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))