mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
Displayed related history suggestions in detailed history view
This commit is contained in:
parent
875a43ed01
commit
d6727d18e5
3 changed files with 44 additions and 17 deletions
|
@ -215,16 +215,26 @@ class MachineHistorySearch:
|
||||||
|
|
||||||
|
|
||||||
class RelatedHistory:
|
class RelatedHistory:
|
||||||
def __init__(self, model_name, object_id, detailed=True):
|
def __init__(self, name, instance, detailed=True):
|
||||||
"""
|
"""
|
||||||
:param model_name: Name of the related model (e.g. "user")
|
:param model_name: Name of the related model (e.g. "user")
|
||||||
:param object_id: ID of the related object
|
:param object_id: ID of the related object
|
||||||
:param detailed: Whether the related history should be shown in an detailed view
|
:param detailed: Whether the related history should be shown in an detailed view
|
||||||
"""
|
"""
|
||||||
self.model_name = model_name
|
self.name = name
|
||||||
self.object_id = object_id
|
self.instance = instance
|
||||||
self.detailed = detailed
|
self.detailed = detailed
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return (
|
||||||
|
self.name == other.name
|
||||||
|
and self.instance.id == other.instance.id
|
||||||
|
and self.detailed == other.detailed
|
||||||
|
)
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash((self.name, self.instance.id, self.detailed))
|
||||||
|
|
||||||
|
|
||||||
class HistoryEvent:
|
class HistoryEvent:
|
||||||
def __init__(self, version, previous_version=None, edited_fields=None):
|
def __init__(self, version, previous_version=None, edited_fields=None):
|
||||||
|
@ -454,14 +464,12 @@ class UserHistory(History):
|
||||||
|
|
||||||
# Add as "related" histories the list of Machine objects
|
# Add as "related" histories the list of Machine objects
|
||||||
# that were once owned by this user
|
# that were once owned by this user
|
||||||
self.related = list(filter(
|
self.related = filter(
|
||||||
lambda x: x.field_dict["user_id"] == user.id,
|
lambda x: x.field_dict["user_id"] == user.id,
|
||||||
Version.objects.get_for_model(Machine).order_by("revision__date_created")
|
Version.objects.get_for_model(Machine).order_by("revision__date_created")
|
||||||
))
|
|
||||||
self.related = sorted(
|
|
||||||
list(dict.fromkeys(self.related)),
|
|
||||||
key=lambda r: r.model_name
|
|
||||||
)
|
)
|
||||||
|
self.related = [RelatedHistory(m.get_name(), m) for m in self.related]
|
||||||
|
self.related = list(dict.fromkeys(self.related))
|
||||||
|
|
||||||
# Get all the versions for this user, with the oldest first
|
# Get all the versions for this user, with the oldest first
|
||||||
self._last_version = None
|
self._last_version = None
|
||||||
|
@ -538,8 +546,6 @@ class MachineHistory(History):
|
||||||
self.event_type = MachineHistoryEvent
|
self.event_type = MachineHistoryEvent
|
||||||
|
|
||||||
def get(self, machine):
|
def get(self, machine):
|
||||||
super(MachineHistory, self).get(machine)
|
|
||||||
|
|
||||||
# Add as "related" histories the list of Interface objects
|
# Add as "related" histories the list of Interface objects
|
||||||
# that were once assigned to this machine
|
# that were once assigned to this machine
|
||||||
self.related = list(filter(
|
self.related = list(filter(
|
||||||
|
@ -547,11 +553,11 @@ class MachineHistory(History):
|
||||||
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
||||||
))
|
))
|
||||||
|
|
||||||
# Remove duplicates and sort
|
# Create RelatedHistory objects and remove duplicates
|
||||||
self.related = sorted(
|
self.related = [RelatedHistory(i.mac_address, i) for i in self.related]
|
||||||
list(dict.fromkeys(self.related)),
|
self.related = list(dict.fromkeys(self.related))
|
||||||
key=lambda r: r.model_name
|
|
||||||
)
|
return super(MachineHistory, self).get(machine)
|
||||||
|
|
||||||
|
|
||||||
class InterfaceHistoryEvent(HistoryEvent):
|
class InterfaceHistoryEvent(HistoryEvent):
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
{% extends 'logs/sidebar.html' %}
|
|
||||||
{% comment %}
|
{% comment %}
|
||||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||||
se veut agnostique au réseau considéré, de manière à être installable en
|
se veut agnostique au réseau considéré, de manière à être installable en
|
||||||
|
@ -73,6 +72,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% else %}
|
{% else %}
|
||||||
<h3>{% trans "No event" %}</h3>
|
<h3>{% trans "No event" %}</h3>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<h2>{% trans Related history %}</h2>
|
||||||
|
|
||||||
|
{% if related_history %}
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "ID" %}</th>
|
||||||
|
<th>{% trans "Actions" %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for related in related_history %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ related.name }}</td>
|
||||||
|
<td>{% history_button related.instance text=True detailed=related.detailed %}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% include 'pagination.html' with list=events %}
|
||||||
|
{% else %}
|
||||||
|
<h3>{% trans "No related history" %}</h3>
|
||||||
|
{% endif %}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -574,7 +574,7 @@ def detailed_history(request, object_name, object_id):
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"logs/detailed_history.html",
|
"logs/detailed_history.html",
|
||||||
{"object": instance, "events": events},
|
{"object": instance, "events": events, "related_history": history.related},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue