Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 26, 2024
1 parent d466c6e commit 6f0f9af
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
14 changes: 12 additions & 2 deletions auditlog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}),
]

Expand Down
6 changes: 3 additions & 3 deletions auditlog/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion auditlog/migrations/0016_add_actor_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
]
4 changes: 3 additions & 1 deletion auditlog/migrations/0017_add_custom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
]
1 change: 0 additions & 1 deletion auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ class Action:

objects = LogEntryManager()


class Meta:
get_latest_by = "timestamp"
ordering = ["-timestamp"]
Expand Down
13 changes: 8 additions & 5 deletions auditlog_tests/test_two_step_json_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ def call_command(self, *args, **kwargs):

@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()
Expand Down
2 changes: 1 addition & 1 deletion auditlog_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def test_set_actor_set_custom_data(self):

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 = [
Expand Down

0 comments on commit 6f0f9af

Please sign in to comment.