Scott Baker | 76a840e | 2015-02-11 21:38:09 -0800 | [diff] [blame^] | 1 | from xos.config import Config |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 2 | |
| 3 | try: |
| 4 | observer_disabled = Config().observer_disabled |
| 5 | except: |
| 6 | observer_disabled = False |
| 7 | |
Scott Baker | fbe0cd7 | 2014-11-19 18:01:13 -0800 | [diff] [blame] | 8 | def EnableObserver(x): |
| 9 | """ used for manage.py --noobserver """ |
| 10 | global observer_disabled |
| 11 | observer_disabled = not x |
| 12 | |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 13 | print_once = True |
| 14 | |
Scott Baker | fbe0cd7 | 2014-11-19 18:01:13 -0800 | [diff] [blame] | 15 | def notify_observer(model=None, delete=False, pk=None, model_dict={}): |
| 16 | if (observer_disabled): |
Scott Baker | f1de7ea | 2014-02-05 09:27:50 -0800 | [diff] [blame] | 17 | global print_once |
Scott Baker | be8907d | 2014-02-05 09:25:44 -0800 | [diff] [blame] | 18 | if (print_once): |
| 19 | print "The observer is disabled" |
| 20 | print_once = False |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 21 | return |
Scott Baker | fbe0cd7 | 2014-11-19 18:01:13 -0800 | [diff] [blame] | 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 | |