Esempio n. 1
0
    def __call__(self, context):
        self.context = context
        self.REQUEST = context.REQUEST
        terms = [SimpleTerm('_default_view',
                            title=_('Default Content View'))]
        views = self._get_views(context)
        for key, title in views:
            terms.append(
                SimpleTerm(
                    key,
                    title=_(title)))

        return SimpleVocabulary(terms)
class ISetLayoutAction(Interface):
    """ Configuration available for this content rule
    """
    layout = Choice(
        title=_(u"Layout"),
        description=_(u"Select the layout to be applied to the "
                      u"content item. If no Content Type condition"
                      u" was created for this rule, only Default "
                      u"View will be available. Also, if more than"
                      u" one content type is selected in the "
                      u" Type condition, an intersection of all "
                      u"selected content type views will be "
                      u"available to this action."),
        required=True,
        vocabulary='sc.contentrules.layout.available_views',
    )
    def __call__(self):
        '''  Apply selected layout to a content item
        '''
        context = self.context
        self._pstate = context.unrestrictedTraverse('@@plone_portal_state')
        self._ptools = context.unrestrictedTraverse('@@plone_tools')
        pt = self._ptools.types()
        layout = self.element.layout

        if layout == '_default_view':
            # Do nothing, leave layout with default view
            return True

        # Get event object
        obj = self.event.object

        # Content portal_type
        obj_type = obj.portal_type
        fti = pt[obj_type]
        available_layouts = fti.getAvailableViewMethods(obj)

        if not (layout in available_layouts):
            self.error(obj, _(u"Layout ${layout} is not available for "
                              u"${portal_type}.",
                       mapping={'layout': layout,
                                'portal_type': obj_type}))
            return False

        # Set Layout
        obj.setLayout(layout)
        return True
 def summary(self):
     return _(u"Set layout ${layout} to a content item",
              mapping=dict(layout=self.layout))