mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-16 00:13:12 +00:00
Make related history more extensive for users and machines
This commit is contained in:
parent
de23ed7e03
commit
c3e246c64d
1 changed files with 15 additions and 8 deletions
|
@ -301,6 +301,9 @@ class RelatedHistory:
|
||||||
self.object_id = version.object_id
|
self.object_id = version.object_id
|
||||||
self.name = version.object_repr
|
self.name = version.object_repr
|
||||||
|
|
||||||
|
if self.model_name:
|
||||||
|
self.name = "{}: {}".format(self.model_name.title(), self.name)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (
|
return (
|
||||||
self.model_name == other.model_name
|
self.model_name == other.model_name
|
||||||
|
@ -643,11 +646,14 @@ class UserHistory(History):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Add in "related" elements the list of Machine objects
|
# Add in "related" elements the list of objects
|
||||||
# that were once owned by this user
|
# that were once owned by this user
|
||||||
|
query = Q(serialized_data__contains='"user": {}'.format(user_id))
|
||||||
|
query &= ~Q(serialized_data__contains='"model": "users.user"')
|
||||||
self.related = (
|
self.related = (
|
||||||
Version.objects.get_for_model(Machine)
|
Version.objects.all()
|
||||||
.filter(serialized_data__contains='"user": {}'.format(user_id))
|
.filter(query)
|
||||||
|
.order_by("content_type__model")
|
||||||
)
|
)
|
||||||
self.related = [RelatedHistory(v) for v in self.related]
|
self.related = [RelatedHistory(v) for v in self.related]
|
||||||
self.related = list(dict.fromkeys(self.related))
|
self.related = list(dict.fromkeys(self.related))
|
||||||
|
@ -732,12 +738,13 @@ class MachineHistory(History):
|
||||||
self.event_type = MachineHistoryEvent
|
self.event_type = MachineHistoryEvent
|
||||||
|
|
||||||
def get(self, machine_id, model):
|
def get(self, machine_id, model):
|
||||||
# Add as "related" histories the list of Interface objects
|
query = Q(serialized_data__contains='"machine": {}'.format(machine_id))
|
||||||
# that were once assigned to this machine
|
query &= ~Q(serialized_data__contains='"model": "machines.machine"')
|
||||||
self.related = list(
|
|
||||||
|
self.related = (
|
||||||
Version.objects.get_for_model(Interface)
|
Version.objects.get_for_model(Interface)
|
||||||
.filter(serialized_data__contains='"machine": {}'.format(machine_id))
|
.filter(query)
|
||||||
.order_by("-revision__date_created")
|
.order_by("content_type__model")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create RelatedHistory objects and remove duplicates
|
# Create RelatedHistory objects and remove duplicates
|
||||||
|
|
Loading…
Reference in a new issue