mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Add title to history of deleted objects
This commit is contained in:
parent
bd06ee3327
commit
47c5f0cc54
3 changed files with 21 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% block title %}{% trans "History" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% blocktrans %}History of {{ object }}{% endblocktrans %}</h2>
|
||||
<h2>{% blocktrans %}History of {{ title }}{% endblocktrans %}</h2>
|
||||
|
||||
{% if events %}
|
||||
<table class="table table-striped">
|
||||
|
|
|
@ -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},
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue