|
|
@@ -15,6 +15,7 @@ from core.choices import JobStatusChoices
|
|
|
from core.models import ContentType
|
|
|
from extras.choices import *
|
|
|
from extras.utils import is_taggable, register_features
|
|
|
+from netbox.config import get_config
|
|
|
from netbox.registry import registry
|
|
|
from netbox.signals import post_clean
|
|
|
from utilities.json import CustomFieldJSONEncoder
|
|
|
@@ -63,19 +64,26 @@ class ChangeLoggingMixin(models.Model):
|
|
|
class Meta:
|
|
|
abstract = True
|
|
|
|
|
|
- def serialize_object(self):
|
|
|
+ def serialize_object(self, exclude=None):
|
|
|
"""
|
|
|
Return a JSON representation of the instance. Models can override this method to replace or extend the default
|
|
|
serialization logic provided by the `serialize_object()` utility function.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ exclude: An iterable of attribute names to omit from the serialized output
|
|
|
"""
|
|
|
- return serialize_object(self)
|
|
|
+ return serialize_object(self, exclude=exclude or [])
|
|
|
|
|
|
def snapshot(self):
|
|
|
"""
|
|
|
Save a snapshot of the object's current state in preparation for modification. The snapshot is saved as
|
|
|
`_prechange_snapshot` on the instance.
|
|
|
"""
|
|
|
- self._prechange_snapshot = self.serialize_object()
|
|
|
+ exclude_fields = []
|
|
|
+ if get_config().CHANGELOG_SKIP_EMPTY_CHANGES:
|
|
|
+ exclude_fields = ['last_updated',]
|
|
|
+
|
|
|
+ self._prechange_snapshot = self.serialize_object(exclude=exclude_fields)
|
|
|
snapshot.alters_data = True
|
|
|
|
|
|
def to_objectchange(self, action):
|
|
|
@@ -84,6 +92,11 @@ class ChangeLoggingMixin(models.Model):
|
|
|
by ChangeLoggingMiddleware.
|
|
|
"""
|
|
|
from extras.models import ObjectChange
|
|
|
+
|
|
|
+ exclude = []
|
|
|
+ if get_config().CHANGELOG_SKIP_EMPTY_CHANGES:
|
|
|
+ exclude = ['last_updated']
|
|
|
+
|
|
|
objectchange = ObjectChange(
|
|
|
changed_object=self,
|
|
|
object_repr=str(self)[:200],
|
|
|
@@ -92,7 +105,7 @@ class ChangeLoggingMixin(models.Model):
|
|
|
if hasattr(self, '_prechange_snapshot'):
|
|
|
objectchange.prechange_data = self._prechange_snapshot
|
|
|
if action in (ObjectChangeActionChoices.ACTION_CREATE, ObjectChangeActionChoices.ACTION_UPDATE):
|
|
|
- objectchange.postchange_data = self.serialize_object()
|
|
|
+ objectchange.postchange_data = self.serialize_object(exclude=exclude)
|
|
|
|
|
|
return objectchange
|
|
|
|