mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
d466c6efe6
commit
6f0f9afa91
7 changed files with 31 additions and 14 deletions
|
|
@ -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"]}),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -382,7 +382,6 @@ class LogEntry(models.Model):
|
|||
|
||||
objects = LogEntryManager()
|
||||
|
||||
|
||||
class Meta:
|
||||
get_latest_by = "timestamp"
|
||||
ordering = ["-timestamp"]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue