pass pk to deleter, support model as a class or instance, give each event a uuid, fix delete_flag name, fix arg passing to fire
diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py
index b64df5f..94c3d5a 100644
--- a/planetstack/core/models/plcorebase.py
+++ b/planetstack/core/models/plcorebase.py
@@ -1,6 +1,7 @@
import os
from django.db import models
from django.forms.models import model_to_dict
+from django.core.urlresolvers import reverse
# This is a no-op if observer_disabled is set to 1 in the config file
from observer import *
@@ -40,7 +41,7 @@
super(PlCoreBase, self).delete(*args, **kwds)
# This is a no-op if observer_disabled is set
- notify_observer(model=self, delete=True)
+ notify_observer(model=self, delete=True, pk=self.pk)
def save(self, *args, **kwargs):
super(PlCoreBase, self).save(*args, **kwargs)
diff --git a/planetstack/observer/__init__.py b/planetstack/observer/__init__.py
index b23caf2..e2a93de 100644
--- a/planetstack/observer/__init__.py
+++ b/planetstack/observer/__init__.py
@@ -10,10 +10,14 @@
if (not observer_disabled):
from .event_manager import EventSender
- def notify_observer(model=None, delete=False):
+ def notify_observer(model=None, delete=False, pk=None):
try:
if (model and delete):
- EventSender().fire({'delete_flag':delete,'model':model.__name__})
+ if hasattr(model,"__name__"):
+ modelName = model.__name__
+ else:
+ modelName = model.__class__.__name__
+ EventSender().fire(delete_flag = delete, model = modelName, pk = pk)
else:
EventSender().fire()
except Exception,e:
@@ -21,7 +25,7 @@
else:
def notify_observer(model=None, delete=False):
- if (print_once):
- print "The observer is disabled"
- print_once = False
+# if (print_once):
+# print "The observer is disabled"
+# print_once = False
return
diff --git a/planetstack/observer/event_manager.py b/planetstack/observer/event_manager.py
index a885fb5..8ec3fc2 100644
--- a/planetstack/observer/event_manager.py
+++ b/planetstack/observer/event_manager.py
@@ -4,6 +4,7 @@
from planetstack.config import Config
from observer.deleters import deleters
+import uuid
import os
import base64
from fofum import Fofum
@@ -49,8 +50,10 @@
self.fofum = Fofum(user=user)
self.fofum.make(clid)
- def fire(self,**args):
- self.fofum.fire(json.dumps(args))
+ def fire(self,**kwargs):
+ kwargs["uuid"] = str(uuid.uuid1())
+ print "YYY fire", kwargs
+ self.fofum.fire(json.dumps(kwargs))
class EventListener:
def __init__(self,wake_up=None):
@@ -61,26 +64,30 @@
payload_dict = json.loads(payload)
try:
- deletion = payload_dict['deletion_flag']
+ deletion = payload_dict.get('delete_flag', False)
+ print "XXX", payload_dict, deletion
if (deletion):
model = payload_dict['model']
pk = payload_dict['pk']
+ print "XXX", model, pk, deleters
+
for deleter in deleters[model]:
+ print "ZZZ executing deleter"
deleter(pk)
except:
deletion = False
if (not deletion and self.wake_up):
self.wake_up()
-
+
def random_client_id(self):
try:
return self.client_id
except AttributeError:
self.client_id = base64.urlsafe_b64encode(os.urandom(12))
return self.client_id
-
+
def run(self):
# This is our unique client id, to be used when firing and receiving events
# It needs to be generated once and placed in the config file