Пример #1
0
    def __call__(self, milestone=None):
        context = aq_inner(self.context)
        self.can_edit = api.user.has_permission(
            'Modify portal content', obj=context)
        modified, errors = dexterity_update(context)
        self.workspace = parent_workspace(context)

        if self.workspace.is_case:
            if self.can_edit and milestone is not None \
               and milestone != context.milestone:
                context.milestone = milestone
                modified = True

        if modified:
            api.portal.show_message(
                _("Your changes have been saved."),
                request=self.request,
                type="success",
            )
            context.reindexObject()
            notify(ObjectModifiedEvent(context))

        if errors:
            api.portal.show_message(
                _("There was an error."), request=self.request, type="error")

        return super(TodoView, self).__call__()
Пример #2
0
    def edit(self):
        """
        Edit content and return url. Uses dexterity_update to set the
        appropriate fields after creation.
        """
        modified, errors = dexterity_update(self.context, self.request)
        if modified and not errors:
            api.portal.show_message(
                _("Item edited."), request=self.request, type="success")
            self.context.reindexObject()
            notify(ObjectModifiedEvent(self.context))

        if errors:
            api.portal.show_message(
                _("There was a problem: %s." % errors),
                request=self.request,
                type="error",
            )

        return self.context.absolute_url()
Пример #3
0
    def update(self):
        """ """
        context = aq_inner(self.context)
        modified = False
        errors = None
        messages = []

        if (
                self.request.get('workflow_action') and
                not self.request.get('form.submitted')):
            api.content.transition(
                obj=context,
                transition=self.request.get('workflow_action')
            )
            # re-calculate can_edit after the workflow state change
            self.can_edit = api.user.has_permission(
                'Modify portal content',
                obj=context
            )
            modified = True
            messages.append("The workflow state has been changed.")

        if self.can_edit:
            mod, errors = dexterity_update(context)
            if mod:
                messages.append("Your changes have been saved.")
            modified = modified or mod

        if errors:
            api.portal.show_message(_(
                "There was a problem: %s" % errors), request=self.request,
                type="error")

        elif modified:
            api.portal.show_message(_(
                ' '.join(messages)), request=self.request,
                type="success")
            context.reindexObject()
            notify(ObjectModifiedEvent(context))
Пример #4
0
 def update(self):
     """ """
     if ('task_action' in self.request and
             not self.request.get('form.submitted')):
         task_action = self.request.get('task_action')
         if task_action == 'close':
             api.content.transition(
                 obj=self.context,
                 transition='finish'
             )
         elif task_action == 'reopen':
             self.context.reopen()
         api.portal.show_message(_(
             'Changes applied'), request=self.request,
             type="success")
     super(TodoView, self).update()
Пример #5
0
    def create(self):
        """
        Create content and return url. Uses dexterity_update to set the
        appropriate fields after creation.
        """
        form = self.request.form
        new = None
        if self.portal_type == 'ploneintranet.workspace.case':
            template_id = form.get('template_id')
            if template_id:
                portal = api.portal.get()
                template_folder = portal.restrictedTraverse(TEMPLATES_FOLDER)
                if template_folder:
                    src = template_folder.restrictedTraverse(template_id)
                    if src:
                        title = form.get('title')
                        target_id = idnormalizer.normalize(title)
                        target_folder = portal.restrictedTraverse('workspaces')
                        new = api.content.copy(
                            source=src,
                            target=target_folder,
                            id=target_id,
                            safe_id=True,
                        )
            else:
                api.portal.show_message(
                    _('Please specify which Case Template to use'),
                    request=self.request,
                    type="error",
                )
        else:
            container = self.context
            new = api.content.create(
                container=container,
                type=self.portal_type,
                title=self.title,
                safe_id=True,
            )

        if not new:
            return self.context.absolute_url()

        if self.portal_type == 'ploneintranet.workspace.workspacefolder':
            if 'scenario' in form:
                if form['scenario'] == '1':
                    external_visibility = 'secret'
                    join_policy = 'admin'
                    participant_policy = 'producers'
                elif form['scenario'] == '2':
                    external_visibility = 'private'
                    join_policy = 'team'
                    participant_policy = 'moderators'
                elif form['scenario'] == '3':
                    external_visibility = 'open'
                    join_policy = 'self'
                    participant_policy = 'publishers'
                else:
                    raise AttributeError

                new.set_external_visibility(external_visibility)
                new.join_policy = join_policy
                new.participant_policy = participant_policy

        modified, errors = dexterity_update(new)

        if modified and not errors:
            api.portal.show_message(
                _("Item created."), request=self.request, type="success")
            new.reindexObject()
            notify(ObjectModifiedEvent(new))

        if errors:
            api.portal.show_message(
                _("There was a problem: %s." % errors),
                request=self.request,
                type="error",
            )

        return new.absolute_url()