[CORD-2277] Sending event for deleted models
Change-Id: I23fc2136c30e42decc5d4c540a9dfe9229447d63
diff --git a/xos/core/models/attic/xosbase_header.py b/xos/core/models/attic/xosbase_header.py
index 1840f5e..523dccd 100644
--- a/xos/core/models/attic/xosbase_header.py
+++ b/xos/core/models/attic/xosbase_header.py
@@ -242,22 +242,35 @@
return fields
- def push_redis_event(self):
+ def push_redis_event(self, deleted=False, pk=None):
# Transmit update via Redis
try:
r = redis.Redis("redis")
- # NOTE the redis event has been extended with model properties to facilitate the support of real time notification in the UI
- # keep this monitored for performance reasons and eventually revert it back to fetch model properties via the REST API
+
model = self.serialize_for_redis()
bases = inspect.getmro(self.__class__)
- # bases = [x for x in bases if issubclass(x, XOSBase)]
class_names = ",".join([x.__name__ for x in bases])
+
model['class_names'] = class_names
- payload = json.dumps({'pk': self.pk, 'changed_fields': self.changed_fields, 'object': model}, default=date_handler)
+
+ if not pk:
+ pk = self.pk
+
+ json_dict = {
+ 'pk': pk,
+ 'changed_fields': self.changed_fields,
+ 'object': model
+ }
+
+ if deleted:
+ json_dict['deleted'] = True
+ json_dict['object'] = {'id': pk}
+
+ payload = json.dumps(json_dict, default=date_handler)
r.publish(self.__class__.__name__, payload)
except ConnectionError:
# Redis not running.
- # TODO add log statement
+ log.error('Connection to Redis failed')
pass
# For cascading deletes, we need a Collector that doesn't do fastdelete,
diff --git a/xos/core/models/attic/xosbase_model.py b/xos/core/models/attic/xosbase_model.py
index 022ede0..0250d77 100644
--- a/xos/core/models/attic/xosbase_model.py
+++ b/xos/core/models/attic/xosbase_model.py
@@ -45,7 +45,9 @@
pass
if (purge):
+ pk = self.pk
super(XOSBase, self).delete(*args, **kwds)
+ self.push_redis_event(deleted=True, pk=pk)
else:
if (not self.write_protect ):
self.deleted = True
diff --git a/xos/core/models/core.xproto b/xos/core/models/core.xproto
index 894e2ca..bd4be4b 100644
--- a/xos/core/models/core.xproto
+++ b/xos/core/models/core.xproto
@@ -260,7 +260,8 @@
message Diag (XOSBase) {
- required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the synchronizer", null = False, db_index = False];
+ option gui_hidden = True;
+ required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the synchronizer", null = False, db_index = False];
}