mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Restructure change iterator.
This commit is contained in:
parent
7a7e3d04ab
commit
42b4ea5cb4
1 changed files with 13 additions and 18 deletions
|
|
@ -433,28 +433,23 @@ class AbstractLogEntry(models.Model):
|
|||
"""
|
||||
substrings = []
|
||||
|
||||
if all(
|
||||
isinstance(value, (list, tuple)) and len(value) == 2
|
||||
for value in self.changes_dict.values()
|
||||
):
|
||||
substrings = [
|
||||
"{field_name:s}{colon:s}{old:s}{arrow:s}{new:s}".format(
|
||||
for field, value in sorted(self.changes_dict.items()):
|
||||
if isinstance(value, (list, tuple)) and len(value) == 2:
|
||||
# handle regular field change
|
||||
substring = "{field_name:s}{colon:s}{old:s}{arrow:s}{new:s}".format(
|
||||
field_name=field,
|
||||
colon=colon,
|
||||
old=values[0],
|
||||
old=value[0],
|
||||
arrow=arrow,
|
||||
new=values[1],
|
||||
new=value[1],
|
||||
)
|
||||
for field, values in sorted(self.changes_dict.items())
|
||||
]
|
||||
elif all(
|
||||
isinstance(value, dict) and value.get("type") == "m2m"
|
||||
for value in self.changes_dict.values()
|
||||
):
|
||||
substrings = [
|
||||
f"{field}{colon}{value_dict['operation']} {sorted(value_dict['objects'])}"
|
||||
for field, value_dict in self.changes_dict.items()
|
||||
]
|
||||
substrings.append(substring)
|
||||
elif isinstance(value, dict) and value.get("type") == "m2m":
|
||||
# handle m2m change
|
||||
substring = (
|
||||
f"{field}{colon}{value['operation']} {sorted(value['objects'])}"
|
||||
)
|
||||
substrings.append(substring)
|
||||
|
||||
return separator.join(substrings)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue