Commit cbaa0cc6 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'noc-get-change-instance' into 'master'

datastream: get_changed_instance helper method

See merge request noc/noc!6302
parents dd99981d b267f555
...@@ -91,12 +91,18 @@ def _on_model_change(sender, instance, created=False, *args, **kwargs): ...@@ -91,12 +91,18 @@ def _on_model_change(sender, instance, created=False, *args, **kwargs):
nv = nv.pk nv = nv.pk
return str(ov) != str(nv) return str(ov) != str(nv)
# Check for instance proxying
if hasattr(instance, "get_changed_instance"):
instance = instance.get_changed_instance()
changed_fields = []
else:
changed_fields = [
f_name for f_name in getattr(instance, "initial_data", []) if is_changed(f_name)
]
# Register change
model_id = get_model_id(instance) model_id = get_model_id(instance)
op = "create" if created else "update" op = "create" if created else "update"
logger.debug("[%s|%s] Change detected: %s", model_id, instance.id, op) logger.debug("[%s|%s] Change detected: %s", model_id, instance.id, op)
changed_fields = [
f_name for f_name in getattr(instance, "initial_data", []) if is_changed(f_name)
]
change_tracker.register( change_tracker.register(
op=op, op=op,
model=model_id, model=model_id,
......
...@@ -56,9 +56,8 @@ class DNSZoneRecord(NOCModel): ...@@ -56,9 +56,8 @@ class DNSZoneRecord(NOCModel):
return dnszonerecord[0] return dnszonerecord[0]
return None return None
def iter_changed_datastream(self, changed_fields=None): def get_changed_instance(self):
for ds, id in self.zone.iter_changed_datastream(changed_fields=changed_fields): return self.zone
yield ds, id
@classmethod @classmethod
def can_set_label(cls, label): def can_set_label(cls, label):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment