source: products/quintagroup.portletmanager/trunk/quintagroup/portletmanager/manager.py @ 3652

Last change on this file since 3652 was 344, checked in by chervol, 14 years ago

tag 0.8

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1import sys
2from ZODB.POSException import ConflictError
3
4from zope.interface import Interface
5from zope.component import adapts, getMultiAdapter
6
7from zope.publisher.interfaces.browser import IBrowserView
8from zope.publisher.interfaces.browser import IDefaultBrowserLayer
9
10from Acquisition import  aq_inner,  aq_acquire
11from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
12from Products.CMFCore.utils import getToolByName
13
14from plone.portlets.interfaces import  ILocalPortletAssignable
15
16from plone.app.portlets.interfaces import IColumn
17from plone.app.portlets.interfaces import IDashboard
18from plone.app.portlets.manager import PortletManagerRenderer
19
20import logging
21logger = logging.getLogger('portlets')
22
23class ColumnPortletManagerRenderer(PortletManagerRenderer):
24    """A renderer for the column portlets
25    """
26    adapts(Interface, IDefaultBrowserLayer, IBrowserView, IColumn)
27    template = ViewPageTemplateFile('browser/templates/column.pt')
28    error_message = ViewPageTemplateFile('browser/templates/error_message.pt')
29
30    def _context(self):
31        context = aq_inner(self.context)
32        return context
33
34    def base_url(self):
35        """If context is a default-page, return URL of folder, else
36        return URL of context.
37        """
38        return str(getMultiAdapter((self._context(), self.request,), name=u'absolute_url'))
39
40    def can_manage_portlets(self):
41        context = self._context()
42        if not ILocalPortletAssignable.providedBy(context):
43            return False
44        mtool = getToolByName(context, 'portal_membership')
45        return mtool.checkPermission("Portlets: Manage portlets", context)
46
47    def safe_render(self, portlet_renderer):
48        try:
49            return portlet_renderer.render()
50        except ConflictError:
51            raise
52        except Exception:
53            logger.exception('Error while rendering %r' % (self,))
54            aq_acquire(self, 'error_log').raising(sys.exc_info())
55            return self.error_message()
Note: See TracBrowser for help on using the repository browser.