Matteo Scandolo | ceccb1f | 2017-06-05 10:35:44 -0700 | [diff] [blame^] | 1 | # FIXME this file needs a refactoring |
| 2 | observer_disabled = False |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 3 | |
| 4 | def EnableObserver(x): |
| 5 | """ used for manage.py --noobserver """ |
| 6 | global observer_disabled |
| 7 | observer_disabled = not x |
| 8 | |
| 9 | print_once = True |
| 10 | |
| 11 | def 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 | |