From d3e681a0ef28ca72bfd13cdbeb289d36cb9549bb Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Thu, 23 Apr 2020 12:06:47 +0000 Subject: [PATCH] Fix displaying new user history view --- logs/models.py | 13 ++++-------- logs/templates/logs/user_history.html | 30 ++++++++++++++++----------- logs/urls.py | 2 +- logs/views.py | 10 ++++----- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/logs/models.py b/logs/models.py index 01927de8..0e544215 100644 --- a/logs/models.py +++ b/logs/models.py @@ -256,28 +256,23 @@ class UserHistoryEvent: class UserHistory: def __init__(self): self.events = [] - self.user = None self.__last_version = None - def get(self, user_id): + def get(self, user): """ - :param user_id: id of the user to lookup + :param user: User, the user to lookup :return: list or None, a list of UserHistoryEvent, in reverse chronological order """ self.events = [] - try: - self.user = User.objects.get(id=user_id) - except User.DoesNotExist: - return None # Get all the versions for this user, with the oldest first user_versions = filter( - lambda x: x.field_dict["id"] == user_id, + lambda x: x.field_dict["id"] == user.id, Version.objects.get_for_model(User).order_by("revision__date_created") ) for version in user_versions: - self.__add_revision(self.user, version) + self.__add_revision(user, version) return self.events[::-1] diff --git a/logs/templates/logs/user_history.html b/logs/templates/logs/user_history.html index 6cf86625..b7714978 100644 --- a/logs/templates/logs/user_history.html +++ b/logs/templates/logs/user_history.html @@ -33,28 +33,32 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + {% for event in events %} - + @@ -69,3 +73,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,


+ +{% endblock %} diff --git a/logs/urls.py b/logs/urls.py index adde5d3c..562bd93c 100644 --- a/logs/urls.py +++ b/logs/urls.py @@ -47,5 +47,5 @@ urlpatterns = [ name="history", ), url(r"^stats_search_machine/$", views.stats_search_machine_history, name="stats-search-machine"), - url(r"^user/(?P[0-9]+)$", views.user_history, name="stats-user-history"), + url(r"^user/(?P[0-9]+)$", views.user_history, name="user-history"), ] diff --git a/logs/views.py b/logs/views.py index a36e90cb..25ee7403 100644 --- a/logs/views.py +++ b/logs/views.py @@ -99,7 +99,7 @@ from re2o.utils import ( all_active_interfaces_count, ) from re2o.base import re2o_paginator, SortTable -from re2o.acl import can_view_all, can_view_app, can_edit_history +from re2o.acl import can_view_all, can_view_app, can_edit_history, can_view from .models import MachineHistory, UserHistory from .forms import MachineHistoryForm @@ -509,10 +509,10 @@ def stats_search_machine_history(request): @login_required -@can_view_app("users") -def user_history(request, user_id): +@can_view(User) +def user_history(request, users, **_kwargs): history = UserHistory() - events = history.get(user_id) + events = history.get(users) max_result = GeneralOption.get_cached_value("pagination_number") events = re2o_paginator( @@ -524,7 +524,7 @@ def user_history(request, user_id): return render( request, "logs/user_history.html", - { "user": history.user, "events": events }, + { "user": users, "events": events }, )
{% trans "Performed by" %} {% trans "Date" %}{% trans "Diff" %}{% trans "Performed by" %}{% trans "Edited" %} {% trans "Comment" %}
- - {{ event.performed_by }} - - {{ event.date }} + {% if event.performed_by %} + + {{ event.performed_by }} + + {% else %} + {% trans "Unknown" %} + {% endif %} + {% 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 and edit.2 %} + {{ edit.0 }}: {{ edit.1 }} ➔ {{ edit.2 }}
+ {% elif edit.2 %} + {{ edit.0 }}: {{ edit.2 }}
{% else %} -

{{ edit[0] }}

+ {{ edit.0 }}
{% endif %} {% endfor %}