From e54026c40a56652554c9d7ed12f1a8714c452a2a Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 24 Apr 2020 17:35:48 +0200 Subject: [PATCH] Rework event logs view --- logs/models.py | 32 ++++++++++++++++++++++++- logs/templates/logs/aff_stats_logs.html | 16 +++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/logs/models.py b/logs/models.py index b5d7d080..4aa0bcc4 100644 --- a/logs/models.py +++ b/logs/models.py @@ -25,6 +25,7 @@ from reversion.models import Version, Revision from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import Group from django.db.models import Q +from django.apps import apps from machines.models import IpList from machines.models import Interface @@ -39,6 +40,34 @@ from topologie.models import Port from .forms import classes_for_action_type +class VersionAction: + def __init__(self, version): + self.version = version + + def name(self): + return self.version.object_repr + + def application(self): + return self.version.content_type.app_label + + def model_name(self): + return self.version.content_type.model + + def object_id(self): + return self.version.object_id + + def object_type(self): + return apps.get_model(self.application(), self.model_name()) + + +class RevisionAction: + """A Revision may group multiple Version objects together""" + def __init__(self, revision): + self.performed_by = revision.user + self.revision = revision + self.versions = [VersionAction(v) for v in revision.version_set.all()] + + class ActionsSearch: def get(self, params): """ @@ -65,7 +94,8 @@ class ActionsSearch: if action_models: query &= Q(version__content_type__model__in=action_models) - return ( + return map( + RevisionAction, Revision.objects.all() .filter(query) .select_related("user") diff --git a/logs/templates/logs/aff_stats_logs.html b/logs/templates/logs/aff_stats_logs.html index ab12a02f..c161cdbd 100644 --- a/logs/templates/logs/aff_stats_logs.html +++ b/logs/templates/logs/aff_stats_logs.html @@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Edited object" %} - {% trans "Object type" %} {% trans "Edited by" as tr_edited_by %} {% include 'buttons/sort.html' with prefix='logs' col='author' text=tr_edited_by %} {% trans "Date of editing" as tr_date_of_editing %} @@ -44,11 +43,18 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for revision in revisions_list %} - {% for reversion in revision.version_set.all %} + {% for version in revision.versions %} - {{ reversion.object|truncatechars:20 }} - {{ reversion.content_type.model|truncatechars:20 }} - {{ revision.user }} + + + {{ version.name }} + + + + + {{ revision.user }} + + {{ revision.date_created }} {{ revision.comment }} {% can_edit_history %}