8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Make related history list nicer

This commit is contained in:
Jean-Romain Garnier 2020-04-23 20:00:38 +02:00 committed by Jean-Romain Garnier
parent 6c3d6082b1
commit 8469d758ce
2 changed files with 21 additions and 23 deletions

View file

@ -215,25 +215,25 @@ class MachineHistorySearch:
class RelatedHistory: class RelatedHistory:
def __init__(self, name, instance, detailed=True): def __init__(self, name, model_name, object_id):
""" """
:param name: Name of this instance
: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
""" """
self.name = name self.name = "{} (id = {})".format(name, object_id)
self.instance = instance self.model_name = model_name
self.detailed = detailed self.object_id = object_id
def __eq__(self, other): def __eq__(self, other):
return ( return (
self.name == other.name self.name == other.name
and self.instance.id == other.instance.id and self.model_name == other.model_name
and self.detailed == other.detailed and self.object_id == other.object_id
) )
def __hash__(self): def __hash__(self):
return hash((self.name, self.instance.id, self.detailed)) return hash((self.name, self.model_name, self.object_id))
class HistoryEvent: class HistoryEvent:
@ -468,7 +468,10 @@ class UserHistory(History):
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 = [RelatedHistory(m.field_dict["name"] or _("None"), m) for m in self.related] self.related = [RelatedHistory(
m.field_dict["name"] or _("None"),
"machine",
m.field_dict["id"]) for m in self.related]
self.related = list(dict.fromkeys(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
@ -554,7 +557,10 @@ class MachineHistory(History):
)) ))
# Create RelatedHistory objects and remove duplicates # Create RelatedHistory objects and remove duplicates
self.related = [RelatedHistory(i.field_dict["mac_address"], i) for i in self.related] self.related = [RelatedHistory(
i.field_dict["mac_address"] or _("None"),
"interface",
i.field_dict["id"]) for i in self.related]
self.related = list(dict.fromkeys(self.related)) self.related = list(dict.fromkeys(self.related))
return super(MachineHistory, self).get(machine) return super(MachineHistory, self).get(machine)

View file

@ -78,21 +78,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h2>{% trans "Related history" %}</h2> <h2>{% trans "Related history" %}</h2>
{% if related_history %} {% if related_history %}
<table class="table table-striped"> <ul>
<thead>
<tr>
<th>{% trans "Actions" %}</th>
<th>{% trans "ID" %}</th>
</tr>
</thead>
{% for related in related_history %} {% for related in related_history %}
<tr> <li>
<td>{% history_button related.instance detailed=related.detailed %}</td> <a title="{% trans "History" %}" href="{% url 'logs:detailed-history' related.model_name related.object_id %}">{{ related.name }}</a>
<td>{{ related.name }}</td> </li>
</tr>
{% endfor %} {% endfor %}
</table> </ul>
{% include 'pagination.html' with list=events %}
{% else %} {% else %}
<h3>{% trans "No related history" %}</h3> <h3>{% trans "No related history" %}</h3>
{% endif %} {% endif %}