Пример #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_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"
Пример #3
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'])
Пример #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_obj_none():
    obj_dict = utils.create_dict_with_relations(None)
    assert obj_dict == {}
Пример #6
0
def test_relation():
    author = AuthorFactory()
    book = BookFactory(author=author)
    obj_dict = utils.create_dict_with_relations(author)
    assert obj_dict["books"] == [book.pk]
Пример #7
0
def test_no_relation():
    author = AuthorFactory()
    obj_dict = utils.create_dict_with_relations(author)
    assert obj_dict["books"] == []
Пример #8
0
 def pre_transition(self, instance, action):
     super().pre_transition(instance, action)
     self._pre_save = create_dict_with_relations(instance)
Пример #9
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