Coverage for logs/mixins.py: 81%
12 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-03-29 14:03 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-03-29 14:03 -0600
1from .models import Log
4class LoggingMixin:
5 def _create_log(self, instance, type):
7 data = {k: getattr(instance, k) for k in self.LOGGING_FIELDS} if getattr(self, "LOGGING_FIELDS", None) else None 7 ↛ exitline 7 didn't run the dictionary comprehension on line 7
9 organization = instance.membership.organization if getattr(instance, "membership", None) else None
11 Log.objects.create(
12 user=self.request.user,
13 organization=organization,
14 content_object=instance,
15 action=type,
16 data=data,
17 )
19 def perform_create(self, serializer):
21 instance = serializer.save()
23 self._create_log(instance, Log.ActionChoices.CREATE)
25 def perform_destroy(self, instance):
27 self._create_log(instance, Log.ActionChoices.DELETE)
29 super().perform_destroy(instance)