blob: d9a63beabb17c9a81c64612d498994594e4c2334 [file] [log] [blame]
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -04001from planetstack.config import Config
2
3try:
4 observer_disabled = Config().observer_disabled
5except:
6 observer_disabled = False
7
8print_once = True
9
10if (not observer_disabled):
11 from .event_manager import EventSender
12
Scott Baker6ecd4262014-01-21 23:15:21 -080013 def notify_observer(model=None, delete=False, pk=None, model_dict={}):
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -040014 try:
15 if (model and delete):
Scott Bakerc1c45f82014-01-21 16:23:51 -080016 if hasattr(model,"__name__"):
17 modelName = model.__name__
18 else:
19 modelName = model.__class__.__name__
Scott Baker6ecd4262014-01-21 23:15:21 -080020 EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict)
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -040021 else:
22 EventSender().fire()
23 except Exception,e:
24 print "Exception in Observer. This should not disrupt the front end. %s"%str(e)
25
26else:
Scott Bakerbe8907d2014-02-05 09:25:44 -080027 def notify_observer(model=None, delete=False, pk=None, model_dict={}):
Scott Bakerf1de7ea2014-02-05 09:27:50 -080028 global print_once
Scott Bakerbe8907d2014-02-05 09:25:44 -080029 if (print_once):
30 print "The observer is disabled"
31 print_once = False
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -040032 return