From b1a170f3e4c0f8e39c1f3f637301b1ae303d0210 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Thu, 23 Apr 2020 12:44:23 +0000 Subject: [PATCH] Improve user history view event format --- logs/models.py | 14 ++++++++++---- logs/templates/logs/user_history.html | 13 ++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/logs/models.py b/logs/models.py index c3254503..2eb5b4ca 100644 --- a/logs/models.py +++ b/logs/models.py @@ -232,24 +232,30 @@ class UserHistoryEvent: :param value: the value of the field :return: object """ - if name == "groups" and value is not None: + if name == "groups": + if len(value) == 0: + # Removed all the user's groups + return _("None") + # value is a list of ints groups = [] for gid in value: # Try to get the group name, if it's not deleted try: - groups.append(Group.objects.get(id=gid)) + groups.append(Group.objects.get(id=gid).name) except Group.DoesNotExist: # TODO: Find the group name in the versions? groups.append(_("Deleted")) + + return ", ".join(groups) elif name == "state": if value is not None: - return User.STATES[value] + return User.STATES[value][1] else: return _("Unknown") elif name == "email_state": if value is not None: - return User.EMAIL_STATES[value] + return User.EMAIL_STATES[value][1] else: return _("Unknown") diff --git a/logs/templates/logs/user_history.html b/logs/templates/logs/user_history.html index b7714978..ce492281 100644 --- a/logs/templates/logs/user_history.html +++ b/logs/templates/logs/user_history.html @@ -53,12 +53,15 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for edit in event.edits %} - {% if edit.1 and edit.2 %} - {{ edit.0 }}: {{ edit.1 }} ➔ {{ edit.2 }}
- {% elif edit.2 %} - {{ edit.0 }}: {{ edit.2 }}
+ {% if edit.1 is None and edit.2 is None %} + {{ edit.0 }}
+ {% elif edit.1 is None %} + {{ edit.0 }}: + {{ edit.2 }}
{% else %} - {{ edit.0 }}
+ {{ edit.0 }}: + {{ edit.1 }} + ➔ {{ edit.2 }}
{% endif %} {% endfor %}