8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 15:33:45 +00:00

Add title to history of deleted objects

This commit is contained in:
Jean-Romain Garnier 2020-04-23 21:25:00 +02:00 committed by Jean-Romain Garnier
parent bd06ee3327
commit 47c5f0cc54
3 changed files with 21 additions and 4 deletions

View file

@ -285,6 +285,7 @@ class HistoryEvent:
class History: class History:
def __init__(self): def __init__(self):
self.name = None
self.events = [] self.events = []
self.related = [] # For example, a machine has a list of its interfaces self.related = [] # For example, a machine has a list of its interfaces
self._last_version = None self._last_version = None
@ -491,6 +492,9 @@ class UserHistory(History):
for version in user_versions: for version in user_versions:
self._add_revision(version) self._add_revision(version)
# Update name
self.name = self._last_version.field_dict["pseudo"]
# Do the same thing for the Adherent of Club # Do the same thing for the Adherent of Club
self._last_version = None self._last_version = None
obj_versions = filter( obj_versions = filter(
@ -570,7 +574,12 @@ class MachineHistory(History):
i.field_dict["id"]) for i in self.related] 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_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): class InterfaceHistoryEvent(HistoryEvent):
@ -616,4 +625,9 @@ class InterfaceHistory(History):
self.event_type = InterfaceHistoryEvent self.event_type = InterfaceHistoryEvent
def get(self, interface_id): 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

View file

@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}{% trans "History" %}{% endblock %} {% block title %}{% trans "History" %}{% endblock %}
{% block content %} {% block content %}
<h2>{% blocktrans %}History of {{ object }}{% endblocktrans %}</h2> <h2>{% blocktrans %}History of {{ title }}{% endblocktrans %}</h2>
{% if events %} {% if events %}
<table class="table table-striped"> <table class="table table-striped">

View file

@ -588,10 +588,13 @@ def detailed_history(request, object_name, object_id):
# Add the paginator in case there are many results # Add the paginator in case there are many results
events = re2o_paginator(request, events, max_result) 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( return render(
request, request,
"logs/detailed_history.html", "logs/detailed_history.html",
{"object": instance, "events": events, "related_history": history.related}, {"title": title, "events": events, "related_history": history.related},
) )