mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-29 08:02:24 +00:00
Fix displaying new user history view
This commit is contained in:
parent
cbf688b640
commit
d3e681a0ef
4 changed files with 28 additions and 27 deletions
|
@ -256,28 +256,23 @@ class UserHistoryEvent:
|
||||||
class UserHistory:
|
class UserHistory:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.events = []
|
self.events = []
|
||||||
self.user = None
|
|
||||||
self.__last_version = 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
|
:return: list or None, a list of UserHistoryEvent, in reverse chronological order
|
||||||
"""
|
"""
|
||||||
self.events = []
|
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
|
# Get all the versions for this user, with the oldest first
|
||||||
user_versions = filter(
|
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")
|
Version.objects.get_for_model(User).order_by("revision__date_created")
|
||||||
)
|
)
|
||||||
|
|
||||||
for version in user_versions:
|
for version in user_versions:
|
||||||
self.__add_revision(self.user, version)
|
self.__add_revision(user, version)
|
||||||
|
|
||||||
return self.events[::-1]
|
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">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Performed by" %}</th>
|
|
||||||
<th>{% trans "Date" %}</th>
|
<th>{% trans "Date" %}</th>
|
||||||
<th>{% trans "Diff" %}</th>
|
<th>{% trans "Performed by" %}</th>
|
||||||
|
<th>{% trans "Edited" %}</th>
|
||||||
<th>{% trans "Comment" %}</th>
|
<th>{% trans "Comment" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for event in events %}
|
{% for event in events %}
|
||||||
<tr>
|
<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>{{ 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>
|
<td>
|
||||||
{% for edit in event.edits %}
|
{% for edit in event.edits %}
|
||||||
{% if edit[1] and edit[2] %}
|
{% if edit.1 and edit.2 %}
|
||||||
<p>{{ edit[0] }}: {{ edit[1] }} ➔ {{ edit[2] }}</p>
|
{{ edit.0 }}: {{ edit.1 }} ➔ {{ edit.2 }}<br/>
|
||||||
{% elif edit[2] %}
|
{% elif edit.2 %}
|
||||||
<p>{{ edit[0] }}: {{ edit[2] }}</p>
|
{{ edit.0 }}: {{ edit.2 }}<br/>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ edit[0] }}</p>
|
{{ edit.0 }}<br/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
|
@ -69,3 +73,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -47,5 +47,5 @@ urlpatterns = [
|
||||||
name="history",
|
name="history",
|
||||||
),
|
),
|
||||||
url(r"^stats_search_machine/$", views.stats_search_machine_history, name="stats-search-machine"),
|
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,
|
all_active_interfaces_count,
|
||||||
)
|
)
|
||||||
from re2o.base import re2o_paginator, SortTable
|
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 .models import MachineHistory, UserHistory
|
||||||
from .forms import MachineHistoryForm
|
from .forms import MachineHistoryForm
|
||||||
|
@ -509,10 +509,10 @@ def stats_search_machine_history(request):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_view_app("users")
|
@can_view(User)
|
||||||
def user_history(request, user_id):
|
def user_history(request, users, **_kwargs):
|
||||||
history = UserHistory()
|
history = UserHistory()
|
||||||
events = history.get(user_id)
|
events = history.get(users)
|
||||||
|
|
||||||
max_result = GeneralOption.get_cached_value("pagination_number")
|
max_result = GeneralOption.get_cached_value("pagination_number")
|
||||||
events = re2o_paginator(
|
events = re2o_paginator(
|
||||||
|
@ -524,7 +524,7 @@ def user_history(request, user_id):
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"logs/user_history.html",
|
"logs/user_history.html",
|
||||||
{ "user": history.user, "events": events },
|
{ "user": users, "events": events },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue