예제 #1
0
    def test_migrates_plone_task_responsible_after(self):
        task = create(Builder('task'))

        response = TaskResponse()
        response.add_change('responsible', 'peter', 'HANS.MUSTER')
        IResponseContainer(task).add(response)

        PloneTasksMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        self.assertEquals('hans.muster', response.changes[-1]['after'])
예제 #2
0
    def test_migrates_plone_task_response_creator(self):
        task = create(Builder('task'))

        response = TaskResponse()
        response.creator = 'HANS.MUSTER'
        IResponseContainer(task).add(response)

        PloneTasksMigrator(
            self.portal, {'HANS.MUSTER': 'hans.muster'}, 'move').migrate()

        self.assertEquals('hans.muster', response.creator)
    def test_null_fallback(self, browser):
        # add null response
        null_response = TaskResponse(None)
        IResponseContainer(self.task).add(null_response)
        transaction.commit()

        browser.login()
        self.visit_overview(browser)

        self.assertEqual('answer null-transition',
                         browser.css('div.answer')[0].get('class'))
        self.assertEqual('', self.get_latest_answer(browser))
예제 #4
0
    def create_responses(self, data):
        container = IResponseContainer(self.context)

        for resp_data in data:
            response = TaskResponse('')

            for key, value in resp_data.items():
                if value:
                    value = self._decode(value)
                setattr(response, key, value)

            container.add(response)

        modified(self.context)
예제 #5
0
def add_simple_response(task,
                        text='',
                        field_changes=None,
                        added_objects=None,
                        successor_oguid=None,
                        supress_events=False,
                        supress_activity=False,
                        **kwargs):
    """Add a simple response which does (not change the task itself).
    `task`: task context
    `text`: fulltext
    `added_objects`: objects which were added to the task
    `successor_oguid`: an OGUID to a (remote) object which was referenced.
    """

    response = TaskResponse()
    response.text = text

    for key, value in kwargs.items():
        setattr(response, key, value)

    if field_changes:
        for field, new_value in field_changes:
            old_value = field.get(field.interface(task))
            if old_value != new_value:
                response.add_change(field.__name__,
                                    old_value,
                                    new_value,
                                    field_title=field.title)

    if added_objects:
        intids = getUtility(IIntIds)
        for obj in added_objects:
            iid = intids.getId(obj)
            response.added_objects.append(RelationValue(iid))

    if successor_oguid:
        response.successor_oguid = successor_oguid

    container = IResponseContainer(task)
    container.add(response)

    if not supress_events:
        notify(ObjectModifiedEvent(task))

    if not supress_activity:
        TaskTransitionActivity(task, task.REQUEST, response).record()

    return response
예제 #6
0
    def _create_response(self, text):
        response = TaskResponse(COMMENT_RESPONSE_TYPE)
        response.text = text
        response.transition = self.TRANSITION_TYPE

        return response
예제 #7
0
    def migrate_responses(self, task):
        container = IResponseContainer(task)
        old_container = OldIResponseContainer(task)
        for old_response in old_container:
            response = TaskResponse()

            if old_response.text:
                response.text = old_response.text

            if old_response.rendered_text:
                response.rendered_text = old_response.rendered_text

            if old_response.transition:
                response.transition = old_response.transition

            if old_response.changes:
                for change in old_response.changes:
                    response.add_change(change.get('id'), change.get('before'),
                                        change.get('after'),
                                        change.get('name'))

            if old_response.creator:
                response.creator = old_response.creator

            if old_response.date:
                response.created = old_response.date.asdatetime().replace(
                    tzinfo=None)

            if old_response.type:
                response.response_type = old_response.type

            if old_response.type:
                response.mimetype = old_response.mimetype

            if old_response.relatedItems:
                response.related_items = PersistentList(
                    old_response.relatedItems)

            if old_response.added_object:
                added_objects = old_response.added_object
                if not hasattr(added_objects, '__iter__'):
                    added_objects = [added_objects]

                response.added_objects = PersistentList(added_objects)

            if old_response.successor_oguid:
                response.successor_oguid = old_response.successor_oguid

            container.add(response)

        annotations = IAnnotations(task)
        if old_container.ANNO_KEY in annotations:
            # We do not delete the old responses but backup it in a different
            # annotations-key. As soon as we completely remove the old implementation
            # we can remove the backup. Otherwise we won't have the possibilty to
            # restore any response if there went soemthing wrong.
            # Just leaving the responses under the same key is not an option.
            # Running the upgradestep twice would duplicate the migrated responses.
            annotations['backup-{}'.format(
                old_container.ANNO_KEY)] = annotations[old_container.ANNO_KEY]
            del annotations[old_container.ANNO_KEY]