mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Fix displaying new user history view
This commit is contained in:
parent
d06d6f8c00
commit
3643e06bb3
4 changed files with 28 additions and 27 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -33,28 +33,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Performed by" %}</th>
|
||||
<th>{% trans "Date" %}</th>
|
||||
<th>{% trans "Diff" %}</th>
|
||||
<th>{% trans "Performed by" %}</th>
|
||||
<th>{% trans "Edited" %}</th>
|
||||
<th>{% trans "Comment" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for event in events %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'users:profil' userid=event.performed_by.id %}" title=tr_view_the_profile>
|
||||
{{ event.performed_by }}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ event.date }}</td>
|
||||
<td>
|
||||
{% if event.performed_by %}
|
||||
<a href="{% url 'users:profil' userid=event.performed_by.id %}" title=tr_view_the_profile>
|
||||
{{ event.performed_by }}
|
||||
</a>
|
||||
{% else %}
|
||||
{% trans "Unknown" %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% for edit in event.edits %}
|
||||
{% if edit[1] and edit[2] %}
|
||||
<p>{{ edit[0] }}: {{ edit[1] }} ➔ {{ edit[2] }}</p>
|
||||
{% elif edit[2] %}
|
||||
<p>{{ edit[0] }}: {{ edit[2] }}</p>
|
||||
{% if edit.1 and edit.2 %}
|
||||
{{ edit.0 }}: {{ edit.1 }} ➔ {{ edit.2 }}<br/>
|
||||
{% elif edit.2 %}
|
||||
{{ edit.0 }}: {{ edit.2 }}<br/>
|
||||
{% else %}
|
||||
<p>{{ edit[0] }}</p>
|
||||
{{ edit.0 }}<br/>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
|
@ -69,3 +73,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -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<user_id>[0-9]+)$", views.user_history, name="stats-user-history"),
|
||||
url(r"^user/(?P<userid>[0-9]+)$", views.user_history, name="user-history"),
|
||||
]
|
||||
|
|
|
@ -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 },
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue