blob: e56cd39a5c61a076c72154b5c9617885471b11b6 [file] [log] [blame]
Scott Baker86e132c2015-02-11 21:38:09 -08001from xos.config import Config
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -04002
3try:
4 observer_disabled = Config().observer_disabled
5except:
6 observer_disabled = False
7
Scott Bakerd3a5a2e2014-11-19 18:01:13 -08008def EnableObserver(x):
9 """ used for manage.py --noobserver """
10 global observer_disabled
11 observer_disabled = not x
12
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -040013print_once = True
14
Scott Bakerd3a5a2e2014-11-19 18:01:13 -080015def notify_observer(model=None, delete=False, pk=None, model_dict={}):
16 if (observer_disabled):
Scott Bakerf1de7ea2014-02-05 09:27:50 -080017 global print_once
Scott Bakerbe8907d2014-02-05 09:25:44 -080018 if (print_once):
19 print "The observer is disabled"
20 print_once = False
Sapan Bhatia9c2c8fa2013-10-16 13:26:05 -040021 return
Scott Bakerd3a5a2e2014-11-19 18:01:13 -080022
23 try:
24 from .event_manager import EventSender
25 if (model and delete):
26 if hasattr(model,"__name__"):
27 modelName = model.__name__
28 else:
29 modelName = model.__class__.__name__
30 EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict)
31 else:
32 EventSender().fire()
33 except Exception,e:
34 print "Exception in Observer. This should not disrupt the front end. %s"%str(e)
35
36