mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Show creation event in detailed history
This commit is contained in:
parent
611268255c
commit
23c8b42ab7
1 changed files with 55 additions and 55 deletions
110
logs/models.py
110
logs/models.py
|
@ -42,56 +42,6 @@ from topologie.models import Port
|
|||
from .forms import classes_for_action_type
|
||||
|
||||
|
||||
class ActionsSearch:
|
||||
def get(self, params):
|
||||
"""
|
||||
:param params: dict built by the search view
|
||||
:return: QuerySet of Revision objects
|
||||
"""
|
||||
user = params.get("u", None)
|
||||
start = params.get("s", None)
|
||||
end = params.get("e", None)
|
||||
action_types = params.get("t", None)
|
||||
|
||||
query = Q()
|
||||
|
||||
if user:
|
||||
query &= Q(user__pseudo=user)
|
||||
|
||||
if start:
|
||||
query &= Q(date_created__gte=start)
|
||||
|
||||
if end:
|
||||
query &= Q(date_created__lte=end)
|
||||
|
||||
action_models = self.models_for_action_types(action_types)
|
||||
if action_models:
|
||||
query &= Q(version__content_type__model__in=action_models)
|
||||
|
||||
return (
|
||||
Revision.objects.all()
|
||||
.filter(query)
|
||||
.select_related("user")
|
||||
.prefetch_related("version_set__object")
|
||||
)
|
||||
|
||||
def models_for_action_types(self, action_types):
|
||||
if action_types is None:
|
||||
return None
|
||||
|
||||
classes = []
|
||||
for action_type in action_types:
|
||||
c = classes_for_action_type(action_type)
|
||||
|
||||
# Selecting "all" removes the filter
|
||||
if c is None:
|
||||
return None
|
||||
|
||||
classes += list(map(str.lower, c))
|
||||
|
||||
return classes
|
||||
|
||||
|
||||
class MachineHistorySearchEvent:
|
||||
def __init__(self, user, machine, interface, start=None, end=None):
|
||||
"""
|
||||
|
@ -302,7 +252,7 @@ class RelatedHistory:
|
|||
|
||||
|
||||
class HistoryEvent:
|
||||
def __init__(self, version, previous_version=None, edited_fields=None):
|
||||
def __init__(self, version, previous_version=None, edited_fields=[]):
|
||||
"""
|
||||
:param version: Version, the version of the object for this event
|
||||
:param previous_version: Version, the version of the object before this event
|
||||
|
@ -408,8 +358,8 @@ class History:
|
|||
diff = self._compute_diff(version, self._last_version)
|
||||
|
||||
# Ignore "empty" events
|
||||
if not diff:
|
||||
self._last_version = version
|
||||
# but always keep the first event
|
||||
if not diff and self._last_version:
|
||||
return
|
||||
|
||||
evt = self.event_type(version, self._last_version, diff)
|
||||
|
@ -417,6 +367,56 @@ class History:
|
|||
self._last_version = version
|
||||
|
||||
|
||||
class ActionsSearch:
|
||||
def get(self, params):
|
||||
"""
|
||||
:param params: dict built by the search view
|
||||
:return: QuerySet of Revision objects
|
||||
"""
|
||||
user = params.get("u", None)
|
||||
start = params.get("s", None)
|
||||
end = params.get("e", None)
|
||||
action_types = params.get("t", None)
|
||||
|
||||
query = Q()
|
||||
|
||||
if user:
|
||||
query &= Q(user__pseudo=user)
|
||||
|
||||
if start:
|
||||
query &= Q(date_created__gte=start)
|
||||
|
||||
if end:
|
||||
query &= Q(date_created__lte=end)
|
||||
|
||||
action_models = self.models_for_action_types(action_types)
|
||||
if action_models:
|
||||
query &= Q(version__content_type__model__in=action_models)
|
||||
|
||||
return (
|
||||
Revision.objects.all()
|
||||
.filter(query)
|
||||
.select_related("user")
|
||||
.prefetch_related("version_set__object")
|
||||
)
|
||||
|
||||
def models_for_action_types(self, action_types):
|
||||
if action_types is None:
|
||||
return None
|
||||
|
||||
classes = []
|
||||
for action_type in action_types:
|
||||
c = classes_for_action_type(action_type)
|
||||
|
||||
# Selecting "all" removes the filter
|
||||
if c is None:
|
||||
return None
|
||||
|
||||
classes += list(map(str.lower, c))
|
||||
|
||||
return classes
|
||||
|
||||
|
||||
class VersionAction(HistoryEvent):
|
||||
def __init__(self, version):
|
||||
self.version = version
|
||||
|
@ -685,8 +685,8 @@ class UserHistory(History):
|
|||
)
|
||||
|
||||
# Ignore "empty" events like login
|
||||
if not diff:
|
||||
self._last_version = version
|
||||
# but always keep the first event
|
||||
if not diff and self._last_version:
|
||||
return
|
||||
|
||||
evt = UserHistoryEvent(version, self._last_version, diff)
|
||||
|
|
Loading…
Reference in a new issue