1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #9228: Add serialize_object() method to ChangeLoggingMixin

This commit is contained in:
jeremystretch
2022-07-01 15:52:16 -04:00
parent a5124ab9c8
commit 23f391c5b5
3 changed files with 22 additions and 6 deletions

View File

@ -1,6 +1,5 @@
import hashlib
import hmac
from collections import defaultdict
from django.contrib.contenttypes.models import ContentType
from django.utils import timezone
@ -27,10 +26,18 @@ def serialize_for_webhook(instance):
def get_snapshots(instance, action):
return {
snapshots = {
'prechange': getattr(instance, '_prechange_snapshot', None),
'postchange': serialize_object(instance) if action != ObjectChangeActionChoices.ACTION_DELETE else None,
'postchange': None,
}
if action != ObjectChangeActionChoices.ACTION_DELETE:
# Use model's serialize() method if defined; fall back to serialize_object
if hasattr(instance, 'serialize_object'):
snapshots['postchange'] = instance.serialize_object()
else:
snapshots['postchange'] = serialize_object(instance)
return snapshots
def generate_signature(request_body, secret):