Fixing changed fields in redis events
Change-Id: I90aa0c1931f5a9c6152daebbfd2ae32af23125d3
diff --git a/xos/core/models/attic/xosbase_header.py b/xos/core/models/attic/xosbase_header.py
index 9cb7348..b3efde4 100644
--- a/xos/core/models/attic/xosbase_header.py
+++ b/xos/core/models/attic/xosbase_header.py
@@ -113,8 +113,14 @@
@property
def changed_fields(self):
+ if self.is_new:
+ return self._dict.keys()
return self.diff.keys()
+ @property
+ def is_new(self):
+ return self.pk is None
+
def has_field_changed(self, field_name):
return field_name in self.diff.keys()
@@ -233,21 +239,6 @@
def push_redis_event(self):
# Transmit update via Redis
- changed_fields = []
-
- if self.pk is not None:
- my_model = type(self)
- try:
- orig = my_model.objects.get(pk=self.pk)
-
- for f in my_model._meta.fields:
- oval = getattr(orig, f.name)
- nval = getattr(self, f.name)
- if oval != nval:
- changed_fields.append(f.name)
- except:
- changed_fields.append('__lookup_error')
-
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
@@ -257,10 +248,11 @@
# 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': changed_fields, 'object': model}, default=date_handler)
+ payload = json.dumps({'pk': self.pk, 'changed_fields': self.changed_fields, 'object': model}, default=date_handler)
r.publish(self.__class__.__name__, payload)
except ConnectionError:
# Redis not running.
+ # TODO add log statement
pass
# For cascading deletes, we need a Collector that doesn't do fastdelete,