Improved handling of unregistered portlets
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Jun 2018 15:29:20 +0200 (2018-06-11)
changeset 95 b4e5117061d3
parent 94 4d1da9093bd6
child 96 43a99de860f2
Improved handling of unregistered portlets
src/pyams_portal/portlet.py
--- a/src/pyams_portal/portlet.py	Sun Jun 10 01:46:38 2018 +0200
+++ b/src/pyams_portal/portlet.py	Mon Jun 11 15:29:20 2018 +0200
@@ -129,11 +129,11 @@
 
     def __init__(self, context, request, view, settings):
         super(PortletContentProvider, self).__init__(context, request, view)
+        self.portlet = request.registry.queryUtility(IPortlet, name=settings.configuration.portlet_name)
         self.settings = settings
-        self.portlet = request.registry.getUtility(IPortlet, name=settings.configuration.portlet_name)
 
     def __call__(self):
-        if not self.settings.visible:
+        if (self.portlet is None) or not self.settings.visible:
             return ''
         if self.portlet.permission and not self.request.has_permission(self.portlet.permission):
             return ''
@@ -268,14 +268,17 @@
         parent = self.__parent__
         if IPortalTemplate.providedBy(parent):
             return parent
-        while IPortalContext.providedBy(parent):
-            configuration = IPortalPortletsConfiguration(parent).get_portlet_configuration(self.portlet_id)
-            if not configuration.inherit_parent:
-                return parent
-            page = IPortalPage(parent)
-            if not page.inherit_parent:
+        while True:
+            if IPortalContext.providedBy(parent):
+                configuration = IPortalPortletsConfiguration(parent).get_portlet_configuration(self.portlet_id)
+                if not configuration.inherit_parent:
+                    return parent
+                page = IPortalPage(parent)
+                if not page.inherit_parent:
+                    break
+            parent = parent.__parent__
+            if parent is None:
                 break
-            parent = parent.__parent__
         page = IPortalPage(parent, None)
         if page is not None:
             return page.template