示例#1
0
 def save_model(self, request, obj, form, change):
     pre_save = None
     if hasattr(obj, "pk") and obj.pk is not None:
         pre_save = obj.__class__.objects.get(pk=obj.pk)
     pre_save = create_dict_with_relations(pre_save)
     super().save_model(request, obj, form, change)
     create_snapshot(obj, pre_save, request.user)
示例#2
0
    def test_additional_data(self):
        action_point = ActionPointFactory(status='pre_completed')
        initial_data = create_dict_with_relations(action_point)

        action_point.assigned_to = UserFactory()
        action_point.complete()
        action_point.save()

        author = UserFactory()
        create_snapshot(action_point, initial_data, author)

        self.assertEqual(action_point.history.count(), 1)

        snapshot = action_point.history.first()
        self.assertIn('key_events', snapshot.data)
        self.assertIn(ActionPoint.KEY_EVENTS.status_update, snapshot.data['key_events'])
        self.assertIn(ActionPoint.KEY_EVENTS.reassign, snapshot.data['key_events'])
示例#3
0
def test_create():
    user = UserFactory()
    author = AuthorFactory()
    activity = utils.create_snapshot(author, {}, user)
    assert activity.target == author
    assert activity.action == activity.CREATE
    assert activity.by_user == user
    assert activity.data["name"] == author.name
    assert activity.change == {}
示例#4
0
    def test_additional_data(self):
        action_point = ActionPointFactory(status='pre_completed')
        initial_data = create_dict_with_relations(action_point)

        action_point.assigned_to = UserFactory()
        action_point.complete()
        action_point.save()

        author = UserFactory()
        create_snapshot(action_point, initial_data, author)

        self.assertEqual(action_point.history.count(), 1)

        snapshot = action_point.history.first()
        self.assertIn('key_events', snapshot.data)
        self.assertIn(ActionPoint.KEY_EVENTS.status_update,
                      snapshot.data['key_events'])
        self.assertIn(ActionPoint.KEY_EVENTS.reassign,
                      snapshot.data['key_events'])
示例#5
0
def test_update():
    user = UserFactory()
    author = AuthorFactory()
    obj_dict = utils.create_dict_with_relations(author)
    book = BookFactory(author=author)
    activity = utils.create_snapshot(author, obj_dict, user)
    assert activity.target == author
    assert activity.action == activity.UPDATE
    assert activity.by_user == user
    assert activity.data["name"] == author.name
    assert activity.change == {
        "books": {
            "before": [],
            "after": [book.pk]
        }
    }
    assert activity.get_display() == "Changed books"
示例#6
0
 def post_transition(self, instance, action):
     super().post_transition(instance, action)
     create_snapshot(instance, self._pre_save, self.request.user)
示例#7
0
 def save(self, **kwargs):
     pre_save = create_dict_with_relations(self.instance)
     super().save(**kwargs)
     create_snapshot(self.instance, pre_save, self.context["request"].user)
     return self.instance