Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 1 | from xos.config import Config |
| 2 | |
| 3 | try: |
| 4 | observer_disabled = Config().observer_disabled |
| 5 | except: |
| 6 | observer_disabled = False |
| 7 | |
| 8 | def EnableObserver(x): |
| 9 | """ used for manage.py --noobserver """ |
| 10 | global observer_disabled |
| 11 | observer_disabled = not x |
| 12 | |
| 13 | print_once = True |
| 14 | |
| 15 | def 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 | |