diff --git a/logs/models.py b/logs/models.py index 57597c5b..c41db6b7 100644 --- a/logs/models.py +++ b/logs/models.py @@ -285,6 +285,7 @@ class HistoryEvent: class History: def __init__(self): + self.name = None self.events = [] self.related = [] # For example, a machine has a list of its interfaces self._last_version = None @@ -491,6 +492,9 @@ class UserHistory(History): for version in user_versions: self._add_revision(version) + # Update name + self.name = self._last_version.field_dict["pseudo"] + # Do the same thing for the Adherent of Club self._last_version = None obj_versions = filter( @@ -570,7 +574,12 @@ class MachineHistory(History): i.field_dict["id"]) for i in self.related] self.related = list(dict.fromkeys(self.related)) - return super(MachineHistory, self).get(machine_id, Machine) + events = super(MachineHistory, self).get(machine_id, Machine) + + # Update name + self.name = self._last_version.field_dict["name"] + + return events class InterfaceHistoryEvent(HistoryEvent): @@ -616,4 +625,9 @@ class InterfaceHistory(History): self.event_type = InterfaceHistoryEvent def get(self, interface_id): - return super(InterfaceHistory, self).get(interface_id, Interface) + events = super(InterfaceHistory, self).get(interface_id, Interface) + + # Update name + self.name = self._last_version.field_dict["mac_address"] + + return events diff --git a/logs/templates/logs/detailed_history.html b/logs/templates/logs/detailed_history.html index 26bae90c..7aaf67a0 100644 --- a/logs/templates/logs/detailed_history.html +++ b/logs/templates/logs/detailed_history.html @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block title %}{% trans "History" %}{% endblock %} {% block content %} -

{% blocktrans %}History of {{ object }}{% endblocktrans %}

+

{% blocktrans %}History of {{ title }}{% endblocktrans %}

{% if events %} diff --git a/logs/views.py b/logs/views.py index 007da9f7..ad78bd23 100644 --- a/logs/views.py +++ b/logs/views.py @@ -588,10 +588,13 @@ def detailed_history(request, object_name, object_id): # Add the paginator in case there are many results events = re2o_paginator(request, events, max_result) + # Add a title in case the object was deleted + title = instance or "{} ({})".format(history.name, _("Deleted")) + return render( request, "logs/detailed_history.html", - {"object": instance, "events": events, "related_history": history.related}, + {"title": title, "events": events, "related_history": history.related}, )