Пример #1
0
    def handleSubmit(self, action):
        data, errors = self.extractData()
        if errors:
            errorMessage = '<ul>'
            for error in errors:
                if errorMessage.find(error.message):
                    errorMessage += '<li>' + error.message + '</li>'
            errorMessage += '</ul>'
            self.status = errorMessage
            return None

        else:
            new_response = Response(data.get('text'))
            #define responseTyp
            responseCreator = new_response.creator
            task = aq_inner(self.context)

            if responseCreator == '(anonymous)':
                new_response.type = 'additional'
            if responseCreator == task.Creator():
                new_response.type = 'clarification'

            if data.get('transition', None):
                new_response.transition = data.get('transition', None)

            #if util.getManagersVocab.getTerm(responseCreator):
            #   new_response.type =  'reply'
            #check transition
            if data.get('transition', None) in (
                'task-transition-open-resolved',
                'task-transition-in-progress-resolved'):

                completion_date = datetime.date.today()

            else:
                completion_date = None

            #check other fields
            options = [
                # (task.deadline, data.get('deadline'), 'deadline',
                #  _('deadline')),
                (task.date_of_completion, completion_date,
                 'date_of_completion', _('date_of_completion'))]
            for task_field, resp_field, option, title in options:
                if resp_field and task_field != resp_field:
                    new_response.add_change(option,
                                            title,
                                            task_field,
                                            resp_field)
                    task.__setattr__(option, resp_field)

            # save relatedItems on task
            related_ids = []
            if getattr(task, 'relatedItems'):
                related_ids = [item.to_id for item in task.relatedItems]

            relatedItems = data.get('relatedItems') or []
            intids = getUtility(IIntIds)
            for item in relatedItems:
                to_id = intids.getId(item)
                # relation allready exists
                item._v__is_relation = True
                if to_id not in related_ids:
                    if getattr(task, 'relatedItems'):
                        task.relatedItems.append(RelationValue(to_id))
                    else:
                        setattr(task, 'relatedItems', [RelationValue(to_id)])

                new_response.add_change('relatedItems',
                                        _(u'label_related_items',
                                          default=u"Related Items"),
                                        '',
                                        linked(item, item.Title()))

            # change workflow state of task
            if data.get('transition'):
                wftool = getToolByName(self.context, 'portal_workflow')
                before = wftool.getInfoFor(self.context, 'review_state')
                if data.get('transition') != before:
                    before = wftool.getTitleForStateOnType(before, task.Type())
                    wftool.doActionFor(self.context, data.get('transition'))
                    after = wftool.getInfoFor(self.context, 'review_state')
                    after = wftool.getTitleForStateOnType(after, task.Type())
                    new_response.add_change('review_state', _(u'Issue state'),
                                            before, after)

            container = IResponseContainer(self.context)
            container.add(new_response)

            notify(ObjectModifiedEvent(self.context))

            if data.get('transition'):
                syncer = getMultiAdapter((self.context, self.request),
                                         IWorkflowStateSyncer)
                syncer.change_remote_tasks_workflow_state(
                    data.get('transition'), text=data.get('text'))

            copy_related_documents_view = self.context.restrictedTraverse(
                '@@copy-related-documents-to-inbox')
            if copy_related_documents_view.available():
                url = os.path.join(self.context.absolute_url(),
                                   '@@copy-related-documents-to-inbox')
            else:
                url = self.context.absolute_url()
            self.request.RESPONSE.redirect(url)
            return new_response
Пример #2
0
    def handleSubmit(self, action):
        data, errors = self.extractData()
        if errors:
            errorMessage = '<ul>'
            for error in errors:
                if errorMessage.find(error.message):
                    errorMessage += '<li>' + error.message + '</li>'
            errorMessage += '</ul>'
            self.status = errorMessage
            return None

        else:
            new_response = Response(data.get('text'))
            #define responseTyp
            responseCreator = new_response.creator
            task = aq_inner(self.context)

            if responseCreator == '(anonymous)':
                new_response.type = 'additional'
            if responseCreator == task.Creator():
                new_response.type = 'clarification'

            if data.get('transition', None):
                new_response.transition = data.get('transition', None)

            #if util.getManagersVocab.getTerm(responseCreator):
            #   new_response.type =  'reply'
            #check transition
            if data.get('transition',
                        None) in ('task-transition-open-resolved',
                                  'task-transition-in-progress-resolved'):

                completion_date = datetime.date.today()

            else:
                completion_date = None

            #check other fields
            options = [
                # (task.deadline, data.get('deadline'), 'deadline',
                #  _('deadline')),
                (task.date_of_completion, completion_date,
                 'date_of_completion', _('date_of_completion'))
            ]
            for task_field, resp_field, option, title in options:
                if resp_field and task_field != resp_field:
                    new_response.add_change(option, title, task_field,
                                            resp_field)
                    task.__setattr__(option, resp_field)

            # save relatedItems on task
            related_ids = []
            if getattr(task, 'relatedItems'):
                related_ids = [item.to_id for item in task.relatedItems]

            relatedItems = data.get('relatedItems') or []
            intids = getUtility(IIntIds)
            for item in relatedItems:
                to_id = intids.getId(item)
                # relation allready exists
                item._v__is_relation = True
                if to_id not in related_ids:
                    if getattr(task, 'relatedItems'):
                        task.relatedItems.append(RelationValue(to_id))
                    else:
                        setattr(task, 'relatedItems', [RelationValue(to_id)])

                new_response.add_change(
                    'relatedItems',
                    _(u'label_related_items', default=u"Related Items"), '',
                    linked(item, item.Title()))

            # change workflow state of task
            if data.get('transition'):
                wftool = getToolByName(self.context, 'portal_workflow')
                before = wftool.getInfoFor(self.context, 'review_state')
                if data.get('transition') != before:
                    before = wftool.getTitleForStateOnType(before, task.Type())
                    wftool.doActionFor(self.context, data.get('transition'))
                    after = wftool.getInfoFor(self.context, 'review_state')
                    after = wftool.getTitleForStateOnType(after, task.Type())
                    new_response.add_change('review_state', _(u'Issue state'),
                                            before, after)

            container = IResponseContainer(self.context)
            container.add(new_response)

            notify(ObjectModifiedEvent(self.context))

            if data.get('transition'):
                syncer = getMultiAdapter((self.context, self.request),
                                         IWorkflowStateSyncer)
                syncer.change_remote_tasks_workflow_state(
                    data.get('transition'), text=data.get('text'))

            copy_related_documents_view = self.context.restrictedTraverse(
                '@@copy-related-documents-to-inbox')
            if copy_related_documents_view.available():
                url = os.path.join(self.context.absolute_url(),
                                   '@@copy-related-documents-to-inbox')
            else:
                url = self.context.absolute_url()
            self.request.RESPONSE.redirect(url)
            return new_response
Пример #3
0
    def _create_response(self, text):
        response = Response(text)
        response.transition = self.TRANSITION_TYPE

        return response