def render_edit_manager_panels(self): manager_view = self manager_view.__name__ = 'manage-panels' location = self.context try: settings = getUtility(IRegistry).forInterface(IGlobalSettings) except ComponentLookupError: IStatusMessage(self.request).addStatusMessage( _(u"Unable to find registry."), type="error") except KeyError: IStatusMessage(self.request).addStatusMessage( _(u"Global panel settings unavailable; ignoring."), type="warning") else: # If the panel manager interfaces (aka viewlet managers) are # defined as site-only or navigation-root-only in the settings, # go up the aq_chain to find the panel definition location. for interface in settings.site_local_managers or (): if MANAGER_INTERFACE_TO_NAME[interface] == self.manager_name: while not root_interface().providedBy(location): location = location.aq_parent if location is None: raise RuntimeError("No site found.") panel_manager = PanelManager(self.context, self.request, location, self.manager_name).__of__(self.context) panel_manager_renderer = getMultiAdapter( (self.context, self.request, manager_view, panel_manager), IPanelManagerRenderer) panel_manager_renderer.update() return panel_manager_renderer.render()
def panels(self): location = self.context try: settings = getUtility(IRegistry).forInterface(IGlobalSettings) except ComponentLookupError: IStatusMessage(self.request).addStatusMessage( _(u"Unable to find registry."), type="error") except KeyError: IStatusMessage(self.request).addStatusMessage( _(u"Global panel settings unavailable; ignoring."), type="warning") else: # If the panel manager interfaces (aka viewlet managers) are # defined as site-only or navigation-root-only in the settings, # go up the aq_chain to find the panel definition location. for interface in settings.site_local_managers or (): if interface.providedBy(self.manager): while not self.root_interface.providedBy(location): location = location.aq_parent if location is None: raise RuntimeError("No site found.") # Wrap the panel in an acquisition context that provides # information about which viewlet manager the panel is # implicitly associated with. # TODO - name viewlet-manager and panel-manager explicit manager = PanelManager(self.context, self.request, location, self.normalized_manager_name).__of__( self.context) return tuple(manager)
class ControlPanelEditForm(controlpanel.RegistryEditForm): id = 'PanelsControlPanel' schema = IGlobalSettings fields = field.Fields(IGlobalSettings) schema_prefix = ('collective.panels.interfaces.IGlobalSettings') label = _(u"Configure panels") description = _(u"This form lets you configure the panel add-on product.")
class IPanelLayoutDirective(Interface): name = schema.TextLine(title=_("Name"), required=True) title = schema.TextLine(title=_("Title"), required=True) description = schema.TextLine(title=_("Description"), required=True) template = Path(title=_("Template"), required=True) layer = GlobalInterface( title=_("Layer"), required=True, default=ICollectivePanelsLayer, )
class ManagerVocabulary(object): # Order is important here; the default location will be the first # available (non-hidden) manager. all_viewlet_managers = ( (interfaces.IBelowContentBody, _(u"Below page content")), (interfaces.IAboveContentBody, _(u"Above page content")), (interfaces.IPortalFooter, _(u"Portal footer")), (interfaces.IPortalTop, _(u"Portal top")), ) def __call__(self, context): return SimpleVocabulary([ SimpleTerm(interface, interface.__name__, title) for (interface, title) in self.all_viewlet_managers ])
class PanelManagerSubMenuItem(BrowserSubMenuItem): MANAGE_SETTINGS_PERMISSION = 'Panels: Manage panels' # todo: fix translations title = _(u'manage_panels_link', default=u'Manage panels') submenuId = 'plone_contentmenu_panelmanager' order = 51 def __init__(self, context, request): super(PanelManagerSubMenuItem, self).__init__(context, request) self.context = context self.context_state = getMultiAdapter((context, request), name='plone_context_state') @property def extra(self): # TODO: are the css classes correct? return {'id': 'plone-contentmenu-panelmanager', 'li_class': 'plonetoolbar-panel-manager'} @property def description(self): if self._manageSettings(): return _( u'title_change_panels', default=u'Change the panels of this item' ) else: return u'' @property def action(self): return self.context.absolute_url() + '/manage-panels' @memoize def available(self): secman = getSecurityManager() has_manage_panels_permission = secman.checkPermission( self.MANAGE_SETTINGS_PERMISSION, self.context ) if not has_manage_panels_permission: return False else: # If context can have portlets, it can also have panels. return ILocalPortletAssignable.providedBy(self.context) def selected(self): return False @memoize def _manageSettings(self): secman = getSecurityManager() has_manage_panels_permission = secman.checkPermission( self.MANAGE_SETTINGS_PERMISSION, self.context ) return has_manage_panels_permission
def description(self): if self._manageSettings(): return _( u'title_change_panels', default=u'Change the panels of this item' ) else: return u''
def render_portlets_in_layout(portlets, layout_name, request): """ Render portlets in a layout """ namespace = {'portlets': portlets} try: layout = getAdapter(request, ILayout, name=layout_name) except ComponentLookupError: return _(u"Missing layout: ${layout_name}.", mapping={'layout_name': layout_name}) template = layout['template'] return template.pt_render(namespace)
class IGlobalSettings(Interface): site_local_managers = schema.Set( title=_(u"Site-local panel managers"), description=_(u"The locations listed here will be assignable " u"only at sites (typically Plone's site " u"root, unless local sites are present)."), required=False, value_type=schema.Choice( vocabulary="collective.panels.vocabularies.Managers", )) navigation_local = schema.Bool( title=_(u"Use navigation root"), description=_(u"Site-local panel managers will be assignable " u"on navigation roots instead of only site roots " u"if you select this option. Check this if you are " u"using LinguaPlone, collective.multilingual or " u"similar, and you want per-language Site-local " u"panel managers."), ) css_classes = schema.Tuple( title=_(u"CSS Classes"), description=_(u"Please enter the list of CSS classes, one per line. " u"Format: class or class|descriptive title."), required=False, value_type=schema.TextLine(), )
def add(self): """Add the panel to the panel manager """ context = aq_inner(self.context) manager = aq_base(context) # todo IPortletPermissionChecker(context)() layout = self.request.get('layout', '') if not layout: raise BadRequest("Missing layout.") css_class = self.request.get('css_class', '') heading = safe_unicode(self.request.get('heading', '')) manager.addPanel(layout, css_class, heading) IStatusMessage(self.request).addStatusMessage(_(u"Panel added."), type="info")
def __delitem__(self, name): del self._mapping[name] IStatusMessage(self.request).addStatusMessage(_(u"Panel removed."), type="info")
def title(self): return _(u"Panel ${name} - ${heading}", mapping={ 'name': self.__name__, 'heading': self.heading })