Skip to content

Commit

Permalink
feat: make audit log nicely formatted
Browse files Browse the repository at this point in the history
Use <strong> and <code> to highlight some imporant parts of audit log.
  • Loading branch information
nijel committed Oct 14, 2024
1 parent fe614da commit 21f0f2f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions weblate/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.dispatch import receiver
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.html import format_html
from django.utils.timezone import now
from django.utils.translation import get_language, gettext, gettext_lazy, pgettext_lazy
from django_otp.plugins.otp_static.models import StaticDevice
Expand Down Expand Up @@ -349,7 +350,14 @@ def get_params(self):
result = {
"site_title": settings.SITE_TITLE,
}
result.update(self.params)
for name, value in self.params.items():
if name in {"old", "new", "name", "email", "username"}:
value = format_html("<code>{}</code>", value)
elif name in {"device", "project", "site_title", "method"}:
value = format_html("<strong>{}</strong>", value)

result[name] = value

if "method" in result:
# The gettext is here for legacy entries which contained method name
result["method"] = gettext(get_auth_name(result["method"]))
Expand All @@ -363,7 +371,7 @@ def get_message(self):
message = ACCOUNT_ACTIVITY_METHOD[method][activity]
else:
message = ACCOUNT_ACTIVITY[activity]
return message.format(**self.get_params())
return format_html(message, **self.get_params())

def get_extra_message(self):
if self.activity in EXTRA_MESSAGES:
Expand Down

0 comments on commit 21f0f2f

Please sign in to comment.