From 13cb3f7990aa3258e1493604b8f57ba30113a238 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Sat, 25 Apr 2020 12:59:01 +0200 Subject: [PATCH] Make RelatedHistory cleaner --- logs/models.py | 24 ++++++++---------------- re2o/templates/re2o/aff_history.html | 8 +++++++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/logs/models.py b/logs/models.py index 3f42e6e1..e7d56afa 100644 --- a/logs/models.py +++ b/logs/models.py @@ -289,16 +289,17 @@ class MachineHistorySearch: ############################ class RelatedHistory: - def __init__(self, name, app_name, model_name, object_id): + def __init__(self, version): """ :param name: Name of this instance :param model_name: Name of the related model (e.g. "user") :param object_id: ID of the related object """ - self.name = "{} (id = {})".format(name, object_id) - self.app_name = app_name - self.model_name = model_name - self.object_id = object_id + self.version = version + self.app_name = version.content_type.app_label + self.model_name = version.content_type.model + self.object_id = version.object_id + self.name = version._object_cache or version.object_repr def __eq__(self, other): return ( @@ -646,13 +647,8 @@ class UserHistory(History): self.related = ( Version.objects.get_for_model(Machine) .filter(serialized_data__contains='"user": {}'.format(user_id)) - .order_by("-revision__date_created") ) - self.related = [RelatedHistory( - m.field_dict["name"] or _("None"), - "machines", - "machine", - m.field_dict["id"]) for m in self.related] + self.related = [RelatedHistory(v) for v in self.related] self.related = list(dict.fromkeys(self.related)) # Get all the versions for this user, with the oldest first @@ -744,11 +740,7 @@ class MachineHistory(History): ) # Create RelatedHistory objects and remove duplicates - self.related = [RelatedHistory( - i.field_dict["mac_address"] or _("None"), - "machines", - "interface", - i.field_dict["id"]) for i in self.related] + self.related = [RelatedHistory(v) for v in self.related] self.related = list(dict.fromkeys(self.related)) events = super(MachineHistory, self).get(machine_id, Machine) diff --git a/re2o/templates/re2o/aff_history.html b/re2o/templates/re2o/aff_history.html index b8c8397a..46eb82bc 100644 --- a/re2o/templates/re2o/aff_history.html +++ b/re2o/templates/re2o/aff_history.html @@ -78,7 +78,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,