def update(self):
        self.setUpWidgets()
        self.form_reset = False

        data = {}
        errors, action = self.handleSubmit(self.actions, data, self.validate)
        # the following part will make sure that previous error not
        # get overriden by new errors. This is usefull for subforms. (ri)
        if self.errors is None:
            self.errors = errors
        else:
            if errors is not None:
                self.errors += tuple(errors)

        if errors:
            if (len(errors) == 1) and (isinstance(errors[0], ViewFail)):
                # We send a message if validation of view is false and
                # is the only error.
                self.status = _(u'The view is not available in that container')
                result = action.failure(data, errors)
            else:
                self.status = _(u'There were errors')
                result = action.failure(data, errors)
        elif errors is not None:
            self.form_reset = True
            result = action.success(data)
        else:
            result = None

        self.form_result = result
Пример #2
0
class GroupByDateEditForm(EditForm):
    """
    An edit form for the group by date action
    """
    form_fields = form.FormFields(IGroupByDateAction)
    form_fields['base_folder'].custom_widget = UberSelectionWidget
    label = _(u"Edit group by date action")
    description = _(u"A content rules action to move an item to a folder"
                    u" structure.")
Пример #3
0
class GroupByDateEditForm(ActionEditForm):
    """
    An edit form for the group by date action
    """
    schema = IGroupByDateAction
    label = _(u"Edit group by date action")
    description = _(u"A content rules action to move an item to a folder"
                    u" structure.")
    form_name = _(u'Configure element')
Пример #4
0
class GroupByDateAddForm(ActionAddForm):
    """
    An add form for the group by date action
    """
    schema = IGroupByDateAction
    label = _(u"Add group by date folder action")
    description = _(u"A content rules action to move an item to a folder"
                    u" structure.")
    Type = GroupByDateAction
Пример #5
0
class GroupByDateAddForm(AddForm):
    """
    An add form for the group by date action
    """
    form_fields = form.FormFields(IGroupByDateAction)
    label = _(u"Add group by date folder action")
    description = _(u"A content rules action to move an item to a folder"
                    u" structure.")

    def create(self, data):
        a = GroupByDateAction()
        form.applyChanges(a, self.form_fields, data)
        return a
    def __call__(self):
        '''  Executes action, moving content to a date based folder structure
        '''
        context = self.context
        self._pstate = context.unrestrictedTraverse('@@plone_portal_state')
        self._portal = self._pstate.portal()
        self._portalPath = list(self._portal.getPhysicalPath())

        # Get event object
        obj = self.event.object

        # This should get us a DateTime or a datetime (dexterity)
        objDate = obj.effective_date

        base_folder = self.element.base_folder
        structure = self.element.structure

        folder = self._base_folder(str(base_folder), obj)

        if folder is None:
            self.error(obj, _(u"Base folder ${target} does not exist.",
                       mapping={'target': base_folder}))
            return False

        destFolder = self._createFolderStructure(folder,
                                                 structure, date=objDate)
        destFolderRelPath = self._relPathToPortal(destFolder)

        self.element.target_folder = '/'.join(destFolderRelPath)

        # Move object
        result = super(GroupByDateActionExecutor, self).__call__()
        self.element.target_folder = None
        return result
Пример #7
0
class IGroupByDateAction(Interface):
    """ Configuration options for this content rule action
    """
    base_folder = Choice(
        title=_(u"Base folder"),
        description=_(u"Choose the base folder for the date "
                      u"hierarchy."),
        required=True,
        source=CatalogSource(is_folderish=True),
    )

    container = TextLine(title=_(u"Container"),
                         description=_(
                             u"Select the type of container in which "
                             u"the structure will be based."),
                         default=u'Folder',
                         required=True)

    structure = TextLine(title=_(u"Hierarchy structure"),
                         description=_(u"Choose hierarchy structure. Use "
                                       u"strftime formating. e.g.: '%Y/%m/%d'"
                                       u" to have 2011/11/17 or '%Y/%m' to "
                                       u"have 2011/11"),
                         required=True,
                         default=u'%Y/%m/%d')
Пример #8
0
    def __call__(self):
        """  Executes action, moving content to a date based folder structure
        """
        context = self.context
        self._pstate = context.unrestrictedTraverse('@@plone_portal_state')
        self._portal = self._pstate.portal()
        self._portalPath = list(self._portal.getPhysicalPath())

        # Get event object
        obj = self.event.object

        # This should get us a DateTime or a datetime (dexterity)
        objDate = obj.effective_date

        base_folder = self.element.base_folder
        structure = self.element.structure

        folder = self._base_folder(str(base_folder), obj)

        if folder is None:
            self.error(
                obj,
                _(u"Base folder ${target} does not exist.",
                  mapping={'target': base_folder}))
            return False

        destFolder = self._createFolderStructure(folder,
                                                 structure,
                                                 date=objDate)
        destFolderRelPath = self._relPathToPortal(destFolder)

        self.element.target_folder = '/'.join(destFolderRelPath)

        # get the future id
        # the target folder could be the same
        next_id = obj.id
        if destFolder != aq_parent(obj):
            next_id = self.generate_id(destFolder, obj.id)
        # Move object
        result = super(GroupByDateActionExecutor, self).__call__()
        self.element.target_folder = None
        # notify specific event on new object
        new_obj = destFolder[next_id]
        notify(ObjectGroupedByDate(new_obj))
        return result
    def __call__(self):
        """  Executes action, moving content to a date based folder structure
        """
        context = self.context
        self._pstate = context.unrestrictedTraverse('@@plone_portal_state')
        self._portal = self._pstate.portal()
        self._portalPath = list(self._portal.getPhysicalPath())

        # Get event object
        obj = self.event.object

        # This should get us a DateTime or a datetime (dexterity)
        objDate = obj.effective_date

        base_folder = self.element.base_folder
        structure = self.element.structure

        folder = self._base_folder(str(base_folder), obj)

        if folder is None:
            self.error(obj, _(u"Base folder ${target} does not exist.",
                       mapping={'target': base_folder}))
            return False

        destFolder = self._createFolderStructure(folder,
                                                 structure, date=objDate)
        destFolderRelPath = self._relPathToPortal(destFolder)

        self.element.target_folder = '/'.join(destFolderRelPath)

        # get the future id
        # the target folder could be the same
        next_id = obj.id
        if destFolder != aq_parent(obj):
            next_id = self.generate_id(destFolder, obj.id)
        # Move object
        result = super(GroupByDateActionExecutor, self).__call__()
        self.element.target_folder = None
        # notify specific event on new object
        new_obj = destFolder[next_id]
        notify(ObjectGroupedByDate(new_obj))
        return result
class IGroupByDateAction(Interface):
    """ Configuration options for this content rule action
    """
    base_folder = Choice(title=_(u"Base folder"),
                         description=_(u"Choose the base folder for the date "
                                       u"hierarchy."),
                         required=True,
                         source=SearchableTS({'is_folderish': True},
                                             default_query='path:'))

    container = Choice(title=_(u"Container"),
                       description=_(u"Select the type of container in which "
                                     u"the structure will be based."),
                       source='sc.contentrules.groupbydate.containers',
                       default='Folder',
                       required=True)

    structure = TextLine(title=_(u"Hierarchy structure"),
                         description=_(u"Choose hierarchy structure. Use "
                                       u"strftime formating. e.g.: '%Y/%m/%d'"
                                       u" to have 2011/11/17 or '%Y/%m' to "
                                       u"have 2011/11"),
                         required=True,
                         default=u'%Y/%m/%d')
# -*- coding=utf-8 -*-
from sc.contentrules.groupbydate import MessageFactory as _


PROJECTNAME = "sc.contentrules.groupbydate"

RELPATHVOC = {'../': _(u" One level up"),
              './': _(u' Same folder of content')}
 def summary(self):
     return _(u"Move the item under ${base_folder} using ${structure}"
              u" structure",
             mapping=dict(base_folder=self.base_folder,
                          structure=self.structure))
Пример #13
0
 def summary(self):
     return _(
         u"Move the item under ${base_folder} using ${structure} structure",
         mapping=dict(base_folder=self.base_folder,
                      structure=self.structure))
Пример #14
0
# -*- coding=utf-8 -*-
from sc.contentrules.groupbydate import MessageFactory as _

PROJECTNAME = 'sc.contentrules.groupbydate'

RELPATHVOC = {'../': _(u' One level up'), './': _(u' Same folder of content')}
Пример #15
0
# -*- coding=utf-8 -*-
from sc.contentrules.groupbydate import MessageFactory as _

PROJECTNAME = "sc.contentrules.groupbydate"
GLOBALS = globals()

RELPATHVOC = {'../': _(u" One level up"),
              './': _(u' Same folder of content')}

STRUCTURES = (('ymd', _(u'Year/Month/Day')),
              ('ym', _(u'Year/Month')),
              ('y', _(u'Year')),
              )

DEFAULTPOLICY = 'groupbydate'