from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from plone.app.layout.viewlets.common import ViewletBase from zope.interface import implements, alsoProvides from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewlet from plone.app.layout.globals.interfaces import IViewView from AccessControl import getSecurityManager from Acquisition import aq_base, aq_inner from Products.CMFPlone.utils import safe_unicode from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.CMFCore.utils import getToolByName from cgi import escape from urllib import quote_plus class MemoriesPersonalBarViewlet(ViewletBase): render = ViewPageTemplateFile('memories_personal_bar.pt') def update(self): # set here the values that you need to grab from the template. # stupid example: portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state') context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state') tools = getMultiAdapter((self.context, self.request), name=u'plone_tools') sm = getSecurityManager() self.portal_url = portal_state.portal_url() self.user_actions = context_state.actions().get('user', None) plone_utils = getToolByName(self.context, 'plone_utils') self.getIconFor = plone_utils.getIconFor self.anonymous = portal_state.anonymous() if not self.anonymous: member = portal_state.member() userid = member.getId() self.gender = member.getProperty('gender') if sm.checkPermission('Portlets: Manage own portlets', self.context): self.homelink_url = self.portal_url + '/author/' + quote_plus(userid) else: self.homelink_url = self.portal_url + '/author/' + quote_plus(userid) member_info = tools.membership().getMemberInfo(member.getId()) fullname = member_info.get('fullname', '') if fullname: self.user_name = fullname else: self.user_name = userid class MemoriesContentActionsViewlet(ViewletBase): render = ViewPageTemplateFile('memories_contentactions.pt') def update(self): context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state') self.object_actions = context_state.actions().get('object_actions', []) self.portal_actionicons = getToolByName(self.context, 'portal_actionicons') # The drop-down menus are pulled in via a simple content provider # from plone.app.contentmenu. This behaves differently depending on # whether the view is marked with IViewView. If our parent view # provides that marker, we should do it here as well. if IViewView.providedBy(self.__parent__): alsoProvides(self, IViewView) def icon(self, action): return self.portal_actionicons.renderActionIcon('content_actions', action['id'], None)