Import cleanup
authorThierry Florac <thierry.florac@onf.fr>
Thu, 14 Jun 2018 09:04:09 +0200
changeset 102 b3460ef91e43
parent 101 7cc130cba13c
child 103 8950e51795eb
Import cleanup
src/pyams_portal/interfaces/__init__.py
src/pyams_portal/portlet.py
--- a/src/pyams_portal/interfaces/__init__.py	Wed Jun 13 09:05:14 2018 +0200
+++ b/src/pyams_portal/interfaces/__init__.py	Thu Jun 14 09:04:09 2018 +0200
@@ -79,11 +79,6 @@
 
     configuration = Attribute("Settings parent configuration")
 
-    visible = Bool(title=_("Visible portlet?"),
-                   description=_("Select 'no' to hide this portlet..."),
-                   required=True,
-                   default=True)
-
     renderer = Choice(title=_("Portlet renderer"),
                       description=_("Name of renderer used to render this portlet"),
                       vocabulary='PyAMS portlet renderers',
--- a/src/pyams_portal/portlet.py	Wed Jun 13 09:05:14 2018 +0200
+++ b/src/pyams_portal/portlet.py	Thu Jun 14 09:04:09 2018 +0200
@@ -29,11 +29,12 @@
 # import packages
 from persistent import Persistent
 from persistent.mapping import PersistentMapping
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight
 from pyams_utils.request import check_request
 from pyams_utils.vocabulary import vocabulary_config
 from pyams_viewlet.viewlet import ViewContentProvider
 from pyramid.exceptions import ConfigurationError
+from pyramid.renderers import render
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.copy import clone
@@ -133,7 +134,7 @@
         self.settings = settings
 
     def __call__(self):
-        if (self.portlet is None) or not self.settings.visible:
+        if self.portlet is None:
             return ''
         if self.portlet.permission and not self.request.has_permission(self.portlet.permission):
             return ''
@@ -155,12 +156,19 @@
         slot_id, slot_name = config.get_portlet_slot(self.settings.configuration.portlet_id)
         return config.get_slot_configuration(slot_name)
 
+    def render(self):
+        if self.settings.renderer == 'hidden':
+            return render('templates/portlet-hidden.pt', {}, request=self.request)
+        else:
+            return super(PortletPreviewer, self).render()
+
 
 @implementer(IPortletRenderer)
 class PortletRenderer(PortletContentProvider):
     """Portlet renderer adapter"""
 
     target_interface = None
+    weight = 0
 
     @property
     def slot_configuration(self):
@@ -178,8 +186,9 @@
         request = check_request()
         translate = request.localizer.translate
         terms = [SimpleTerm(name, title=translate(adapter.label))
-                 for name, adapter in request.registry.getAdapters((request.root, request, request, context),
-                                                                   IPortletRenderer)]
+                 for name, adapter in sorted(request.registry.getAdapters((request.root, request, request, context),
+                                                                          IPortletRenderer),
+                                             key=get_adapter_weight)]
         super(PortletRenderersVocabulary, self).__init__(terms)
 
 
@@ -196,7 +205,6 @@
     Each portlet sub-class must define it's settings class in it's "settings_class" attribute.
     """
 
-    visible = FieldProperty(IPortletSettings['visible'])
     _renderer = FieldProperty(IPortletSettings['renderer'])
 
     __name__ = '++settings++'
@@ -205,6 +213,10 @@
         self.__parent__ = configuration
 
     @property
+    def visible(self):
+        return self._renderer != 'hidden'
+
+    @property
     def renderer(self):
         return self._renderer