blob: e56cd39a5c61a076c72154b5c9617885471b11b6 [file] [log] [blame]
Scott Bakerb63ea792016-08-11 10:24:48 -07001from xos.config import Config
2
3try:
4 observer_disabled = Config().observer_disabled
5except:
6 observer_disabled = False
7
8def EnableObserver(x):
9 """ used for manage.py --noobserver """
10 global observer_disabled
11 observer_disabled = not x
12
13print_once = True
14
15def notify_observer(model=None, delete=False, pk=None, model_dict={}):
16 if (observer_disabled):
17 global print_once
18 if (print_once):
19 print "The observer is disabled"
20 print_once = False
21 return
22
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