diff --git a/auditlog/admin.py b/auditlog/admin.py index 079f315..92b9dcb 100644 --- a/auditlog/admin.py +++ b/auditlog/admin.py @@ -29,9 +29,19 @@ class LogEntryAdmin(admin.ModelAdmin, LogEntryAdminMixin): f"actor__{get_user_model().USERNAME_FIELD}", ] list_filter = ["action", ResourceTypeFilter, CIDFilter] - readonly_fields = ["created", "resource_url", "action", "user_url", "msg", "custom_data"] + readonly_fields = [ + "created", + "resource_url", + "action", + "user_url", + "msg", + "custom_data", + ] fieldsets = [ - (None, {"fields": ["created", "user_url", "resource_url", "custom_data", "cid"]}), + ( + None, + {"fields": ["created", "user_url", "resource_url", "custom_data", "cid"]}, + ), (_("Changes"), {"fields": ["action", "msg"]}), ] diff --git a/auditlog/context.py b/auditlog/context.py index 709fda9..af47936 100644 --- a/auditlog/context.py +++ b/auditlog/context.py @@ -28,8 +28,8 @@ def _set_logger_data(actor, kwargs, remote_addr): context_data = auditlog_value.get() except LookupError: context_data = {} - actor = actor or context_data.get('actor') - custom_data = context_data.get('custom_data', {}) + actor = actor or context_data.get("actor") + custom_data = context_data.get("custom_data", {}) custom_data.update(kwargs) """Connect a signal receiver with current user attached.""" context_data = { @@ -38,7 +38,7 @@ def _set_logger_data(actor, kwargs, remote_addr): "custom_data": custom_data, } if actor: - context_data['actor'] = actor + context_data["actor"] = actor token = auditlog_value.set(context_data) # Connect signal for automatic logging set_auditlog_custom_data = partial( diff --git a/auditlog/migrations/0016_add_actor_email.py b/auditlog/migrations/0016_add_actor_email.py index 98e0582..176e376 100644 --- a/auditlog/migrations/0016_add_actor_email.py +++ b/auditlog/migrations/0016_add_actor_email.py @@ -11,7 +11,10 @@ class Migration(migrations.Migration): model_name="logentry", name="actor_email", field=models.CharField( - null=True, verbose_name="actor email", blank=True, max_length=254, + null=True, + verbose_name="actor email", + blank=True, + max_length=254, ), ), ] diff --git a/auditlog/migrations/0017_add_custom_data.py b/auditlog/migrations/0017_add_custom_data.py index 1895c24..13af0e6 100644 --- a/auditlog/migrations/0017_add_custom_data.py +++ b/auditlog/migrations/0017_add_custom_data.py @@ -11,7 +11,9 @@ class Migration(migrations.Migration): model_name="logentry", name="custom_data", field=models.JSONField( - null=True, verbose_name="custom data", blank=True, + null=True, + verbose_name="custom data", + blank=True, ), ), ] diff --git a/auditlog/models.py b/auditlog/models.py index 6aa1c72..01edd87 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -382,7 +382,6 @@ class LogEntry(models.Model): objects = LogEntryManager() - class Meta: get_latest_by = "timestamp" ordering = ["-timestamp"] diff --git a/auditlog_tests/test_two_step_json_migration.py b/auditlog_tests/test_two_step_json_migration.py index afc1877..a93caf5 100644 --- a/auditlog_tests/test_two_step_json_migration.py +++ b/auditlog_tests/test_two_step_json_migration.py @@ -53,11 +53,14 @@ class AuditlogMigrateJsonTest(TestCase): @staticmethod def _remove_formatters(outbuf): - return (outbuf.getvalue().strip() - .replace('\x1b[0m', '') - .replace('\x1b[32;1m', '') - .replace('\x1b[33;1m', '') - .replace('\x1b[31;1m', '')) + return ( + outbuf.getvalue() + .strip() + .replace("\x1b[0m", "") + .replace("\x1b[32;1m", "") + .replace("\x1b[33;1m", "") + .replace("\x1b[31;1m", "") + ) def test_nothing_to_migrate(self): outbuf, errbuf = self.call_command() diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index b8bb672..9ef8281 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -604,7 +604,7 @@ class MiddlewareTest(TestCase): history = obj.history.get() self.assertEqual(history.actor_email, self.user.email) - self.assertEqual(history.custom_data, {'custom_data': {'foo': 'bar'}}) + self.assertEqual(history.custom_data, {"custom_data": {"foo": "bar"}}) def test_get_actor(self): params = [