8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Handle object creation in event logs

This commit is contained in:
Jean-Romain Garnier 2020-04-24 18:23:52 +02:00 committed by Gabriel Detraz
parent 022e9aca93
commit 2a4bea4bbc

View file

@ -430,17 +430,24 @@ class VersionAction(HistoryEvent):
def edits(self, hide=["password", "pwd_ntlm", "gpg_fingerprint"]): def edits(self, hide=["password", "pwd_ntlm", "gpg_fingerprint"]):
self.previous_version = self._previous_version() self.previous_version = self._previous_version()
if self.previous_version is None:
return None, None, None
self.edited_fields = self._compute_diff(self.version, self.previous_version) self.edited_fields = self._compute_diff(self.version, self.previous_version)
return super(VersionAction, self).edits(hide) return super(VersionAction, self).edits(hide)
def _previous_version(self): def _previous_version(self):
model = self.object_type() model = self.object_type()
try:
return next( return next(
filter( filter(
lambda x: x.field_dict["id"] == self.object_id() and x.revision.date_created < self.version.revision.date_created, lambda x: x.field_dict["id"] == self.object_id() and x.revision.date_created < self.version.revision.date_created,
Version.objects.get_for_model(model).order_by("-revision__date_created") Version.objects.get_for_model(model).order_by("-revision__date_created")
) )
) )
except StopIteration:
return None
def _compute_diff(self, v1, v2): def _compute_diff(self, v1, v2):
""" """