Fixes #5913: Improve change logging (#5924)

* Initial work on #5913
* Provide per-line diff highlighting
* BulkDeteView should delete objects individually to secure a pre-change snapshot
* Add changelog tests for bulk operations
This commit is contained in:
Jeremy Stretch
2021-03-04 13:06:04 -05:00
committed by GitHub
parent f495addb1e
commit 9c967ee3ea
21 changed files with 439 additions and 124 deletions

View File

@@ -178,16 +178,18 @@ class ObjectChangeView(generic.ObjectView):
next_change = objectchanges.filter(time__gt=instance.time).order_by('time').first()
prev_change = objectchanges.filter(time__lt=instance.time).order_by('-time').first()
if prev_change:
if instance.prechange_data and instance.postchange_data:
diff_added = shallow_compare_dict(
prev_change.object_data,
instance.object_data,
instance.prechange_data or dict(),
instance.postchange_data or dict(),
exclude=['last_updated'],
)
diff_removed = {x: prev_change.object_data.get(x) for x in diff_added}
diff_removed = {
x: instance.prechange_data.get(x) for x in diff_added
} if instance.prechange_data else {}
else:
# No previous change; this is the initial change that added the object
diff_added = diff_removed = instance.object_data
diff_added = None
diff_removed = None
return {
'diff_added': diff_added,