Exemplo n.º 1
0
 def historyLastEventHasComments(self):
     """See docstring in interfaces.py."""
     lastEvent = getLastAction(self)
     if lastEvent and \
        lastEvent['comments'] and \
        safe_unicode(lastEvent['comments']) not in self.ignorableHistoryComments():
         return True
     return False
Exemplo n.º 2
0
 def print_completeness_date(self, completeness_action, format='%d/%m/%Y'):
     completeness_changes_adapter = getAdapter(self.real_context,
                                               IImioHistory,
                                               'completeness_changes')
     last_action = getLastAction(completeness_changes_adapter,
                                 action=completeness_action)
     if (last_action):
         return last_action['time'].strftime(format)
     else:
         return None
Exemplo n.º 3
0
 def historyLastEventHasComments(self):
     """See docstring in interfaces.py."""
     # for performance reasons, we use checkMayViewEvent=False, checkMayViewComment=False
     # this will do sometimes highlight history in red and last comment is not viewable...
     lastEvent = getLastAction(self)
     if lastEvent and \
        lastEvent['comments'] and \
        safe_unicode(lastEvent['comments']) not in self.ignorableHistoryComments():
         return True
     return False
Exemplo n.º 4
0
 def test_getLastAction_checkMayView(self):
     """Check checkMayViewEvent/checkMayViewComment, default implementation
        returns True."""
     doc = api.content.create(type='Document',
                              id='doc',
                              container=self.portal)
     # publish the doc so we have an new event in the workflow_history
     api.content.transition(doc,
                            'publish',
                            comment='First publication comment')
     adapter = getAdapter(doc, IImioHistory, 'workflow')
     self.assertEqual(
         getLastAction(adapter,
                       checkMayViewEvent=False,
                       checkMayViewComment=False)['action'], 'publish')
     self.assertEqual(
         getLastAction(adapter,
                       checkMayViewEvent=True,
                       checkMayViewComment=True)['action'], 'publish')
     # enable testing-adapter.zcml, the 'publish' actions will
     # not be viewable anymore, as well as revisions
     zcml.load_config('testing-adapter.zcml', imio_history)
     self.request.set('hide_wf_history_event', True)
     self.request.set('hide_wf_history_comment', True)
     adapter = getAdapter(doc, IImioHistory, 'workflow')
     # checkMayViewEvent=False, checkMayViewComment=False
     res = getLastAction(adapter,
                         checkMayViewEvent=False,
                         checkMayViewComment=False)
     self.assertEqual(res['action'], 'publish')
     self.assertEqual(res['comments'], 'First publication comment')
     # checkMayViewEvent=True, checkMayViewComment=True
     self.assertIsNone(
         getLastAction(adapter,
                       checkMayViewEvent=True,
                       checkMayViewComment=True))
     # checkMayViewEvent=False, checkMayViewComment=True
     res = getLastAction(adapter,
                         checkMayViewEvent=False,
                         checkMayViewComment=True)
     self.assertEqual(res['action'], 'publish')
     self.assertEqual(res['comments'], adapter.comment_not_viewable_value)
Exemplo n.º 5
0
    def test_getLastAction(self):
        """Test the utils.getLastAction method.
           It should return the action passed in parameter for the given history name."""
        doc = api.content.create(type='Document',
                                 id='doc',
                                 container=self.portal)
        # publish the doc so we have an new event in the workflow_history
        api.content.transition(doc,
                               'publish',
                               comment='First publication comment')
        adapter = getAdapter(doc, IImioHistory, 'workflow')
        self.assertEqual(getLastAction(adapter)['action'], 'publish')
        # same as getting action with that name
        publish_action = getLastAction(adapter, action='publish')
        self.assertEqual(publish_action['action'], 'publish')
        self.assertEqual(publish_action['comments'],
                         'First publication comment')

        # publish again, check that we correctly get last action
        api.content.transition(doc, 'retract')
        api.content.transition(doc,
                               'publish',
                               comment='Second publication comment')
        # clean memoize
        getattr(adapter, Memojito.propname).clear()
        publish_action = getLastAction(adapter, action='publish')
        self.assertEqual(publish_action['action'], 'publish')
        self.assertEqual(publish_action['comments'],
                         'Second publication comment')

        # the creation event is stored with a None action
        self.assertEqual(
            getLastAction(adapter, action=None)['review_state'], 'private')

        # if action not found, None is returned
        self.assertIsNone(getLastAction(adapter, action='unknown_action'))
Exemplo n.º 6
0
 def test_getLastAction_history_empty(self):
     """Does not breaks and returns None if history empty."""
     adapter = getAdapter(self.portal.folder, IImioHistory, 'revision')
     self.assertIsNone(getLastAction(adapter))