blob: 9b61dfb61a7ca425a9351b2a20c4c2d5254e1a05 [file] [log] [blame]
Matteo Scandoloceccb1f2017-06-05 10:35:44 -07001# FIXME this file needs a refactoring
2observer_disabled = False
Scott Bakerb63ea792016-08-11 10:24:48 -07003
4def EnableObserver(x):
5 """ used for manage.py --noobserver """
6 global observer_disabled
7 observer_disabled = not x
8
9print_once = True
10
11def notify_observer(model=None, delete=False, pk=None, model_dict={}):
12 if (observer_disabled):
13 global print_once
14 if (print_once):
15 print "The observer is disabled"
16 print_once = False
17 return
18
19 try:
20 from .event_manager import EventSender
21 if (model and delete):
22 if hasattr(model,"__name__"):
23 modelName = model.__name__
24 else:
25 modelName = model.__class__.__name__
26 EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict)
27 else:
28 EventSender().fire()
29 except Exception,e:
30 print "Exception in Observer. This should not disrupt the front end. %s"%str(e)
31
32