def __call__(self): """Perform the toggle.""" msg_type = 'info' if ILocalMLSSettings.providedBy(self.context): # Deactivate local MLS settings. noLongerProvides(self.context, ILocalMLSSettings) self.context.reindexObject(idxs=[ 'object_provides', ]) msg = _(u'Local MLS settings deactivated.') elif IPossibleLocalMLSSettings.providedBy(self.context): alsoProvides(self.context, ILocalMLSSettings) self.context.reindexObject(idxs=[ 'object_provides', ]) msg = _(u'Local MLS settings activated.') else: msg = _(u'The local MLS settings don\'t work with this ' u'content type. Add \'IPossibleLocalMLSSettings\' to the ' u'provided interfaces to enable this feature.') msg_type = 'error' self.context.plone_utils.addPortalMessage(msg, msg_type) self.request.response.redirect(self.context.absolute_url())
def _local_settings(context): """Get local MLS settings.""" settings = None if not context or not IPersistent.providedBy(context): request = getRequest() parents = request.get('PARENTS') if len(parents) > 0: context = parents[0] else: context = api.portal.get() obj = context while ( not IPloneSiteRoot.providedBy(obj) and not ILocalMLSSettings.providedBy(obj)): parent = aq_parent(aq_inner(obj)) if parent is None: return obj = parent if ILocalMLSSettings.providedBy(obj): annotations = IAnnotations(obj) settings = annotations.get( CONFIGURATION_KEY, annotations.setdefault(CONFIGURATION_KEY, {})) return settings
def __call__(self): """Perform the toggle.""" msg_type = 'info' if ILocalMLSSettings.providedBy(self.context): # Deactivate local MLS settings. noLongerProvides(self.context, ILocalMLSSettings) self.context.reindexObject(idxs=['object_provides', ]) msg = _(u'Local MLS settings deactivated.') elif IPossibleLocalMLSSettings.providedBy(self.context): alsoProvides(self.context, ILocalMLSSettings) self.context.reindexObject(idxs=['object_provides', ]) msg = _(u'Local MLS settings activated.') else: msg = _( u'The local MLS settings don\'t work with this ' u'content type. Add \'IPossibleLocalMLSSettings\' to the ' u'provided interfaces to enable this feature.' ) msg_type = 'error' self.context.plone_utils.addPortalMessage(msg, msg_type) self.request.response.redirect(self.context.absolute_url())
def active(self): """Is the local MLS configuration active for this context?""" return ILocalMLSSettings.providedBy(self.context)
def can_activate(self): """Can the local MLS configuration be activated for this context?""" return IPossibleLocalMLSSettings.providedBy(self.context) and \ not ILocalMLSSettings.providedBy(self.context)