mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Rework event logs view
This commit is contained in:
parent
6eb8ab637f
commit
e54026c40a
2 changed files with 42 additions and 6 deletions
|
@ -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")
|
||||
|
|
|
@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Edited object" %}</th>
|
||||
<th>{% trans "Object type" %}</th>
|
||||
{% trans "Edited by" as tr_edited_by %}
|
||||
<th>{% include 'buttons/sort.html' with prefix='logs' col='author' text=tr_edited_by %}</th>
|
||||
{% 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.,
|
|||
</tr>
|
||||
</thead>
|
||||
{% for revision in revisions_list %}
|
||||
{% for reversion in revision.version_set.all %}
|
||||
{% for version in revision.versions %}
|
||||
<tr>
|
||||
<td>{{ reversion.object|truncatechars:20 }}</td>
|
||||
<td>{{ reversion.content_type.model|truncatechars:20 }}</td>
|
||||
<td>{{ revision.user }}</td>
|
||||
<td>
|
||||
<a href="{% url 'logs:history' revision.application revision.model_name revision.object_id %}" title="{% trans "History" %}">
|
||||
{{ version.name }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{% url 'users:profil' userid=revision.user.id %}" title=tr_view_the_profile>
|
||||
{{ revision.user }}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ revision.date_created }}</td>
|
||||
<td>{{ revision.comment }}</td>
|
||||
{% can_edit_history %}
|
||||
|
|
Loading…
Reference in a new issue