--- a/src/pyams_viewlet/manager.py Fri Jan 18 10:22:33 2019 +0100
+++ b/src/pyams_viewlet/manager.py Fri Jan 18 10:23:14 2019 +0100
@@ -12,27 +12,24 @@
__docformat__ = 'restructuredtext'
-
-# import standard packages
import logging
-logger = logging.getLogger('PyAMS (viewlet)')
import venusian
-
-# import interfaces
-from pyams_viewlet.interfaces import IViewletManager, IViewlet
+from pyramid.exceptions import ConfigurationError
+from pyramid.httpexceptions import HTTPUnauthorized
from pyramid.interfaces import IRequest, IView
+from pyramid.threadlocal import get_current_registry
from zope.component.interfaces import ComponentLookupError
from zope.contentprovider.interfaces import BeforeUpdateEvent
+from zope.interface import Interface, classImplements, implementer
from zope.location.interfaces import ILocation
-# import packages
from pyams_template.template import get_view_template
from pyams_utils.request import check_request
-from pyramid.exceptions import ConfigurationError
-from pyramid.httpexceptions import HTTPUnauthorized
-from pyramid.threadlocal import get_current_registry
-from zope.interface import implementer, classImplements, Interface
+from pyams_viewlet.interfaces import IViewlet, IViewletManager
+
+
+logger = logging.getLogger('PyAMS (viewlet)')
@implementer(IViewletManager)
@@ -101,20 +98,19 @@
def update(self):
"""See zope.contentprovider.interfaces.IContentProvider"""
- self.__updated = True
-
# check permission
if self.permission and not self.request.has_permission(self.permission, context=self.context):
return
- # Find all content providers for the region
- viewlets = self._get_viewlets()
- # Just use the viewlets from now on
+ # get the viewlets from now on
self.viewlets = []
- for name, viewlet in viewlets:
+ append = self.viewlets.append
+ for name, viewlet in self._get_viewlets():
if ILocation.providedBy(viewlet):
viewlet.__name__ = name
- self.viewlets.append(viewlet)
+ append(viewlet)
+ # and update them...
self._update_viewlets()
+ self.__updated = True
def _get_viewlets(self):
"""Find all content providers for the region"""
@@ -134,11 +130,10 @@
def render(self):
"""See zope.contentprovider.interfaces.IContentProvider"""
- # Now render the view
- if self.permission and not self.request.has_permission(self.permission, context=self.context):
+ # Check for previous update
+ if not (self.__updated and self.viewlets):
return ''
- if not self.viewlets:
- return ''
+ # Now render the view
if self.template:
return self.template(viewlets=self.viewlets)
else:
@@ -207,7 +202,7 @@
class ConditionalViewletManager(WeightOrderedViewletManager):
- """Conditional weight ordered viewlet managers."""
+ """Conditional weight ordered viewlet managers"""
def filter(self, viewlets):
"""Sort out all viewlets which are explicit not available