Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 1 | from planetstack.config import Config |
| 2 | |
| 3 | try: |
| 4 | observer_disabled = Config().observer_disabled |
| 5 | except: |
| 6 | observer_disabled = False |
| 7 | |
| 8 | print_once = True |
| 9 | |
| 10 | if (not observer_disabled): |
| 11 | from .event_manager import EventSender |
| 12 | |
Scott Baker | 6ecd426 | 2014-01-21 23:15:21 -0800 | [diff] [blame] | 13 | def notify_observer(model=None, delete=False, pk=None, model_dict={}): |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 14 | try: |
| 15 | if (model and delete): |
Scott Baker | c1c45f8 | 2014-01-21 16:23:51 -0800 | [diff] [blame] | 16 | if hasattr(model,"__name__"): |
| 17 | modelName = model.__name__ |
| 18 | else: |
| 19 | modelName = model.__class__.__name__ |
Scott Baker | 6ecd426 | 2014-01-21 23:15:21 -0800 | [diff] [blame] | 20 | EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict) |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 21 | else: |
| 22 | EventSender().fire() |
| 23 | except Exception,e: |
| 24 | print "Exception in Observer. This should not disrupt the front end. %s"%str(e) |
| 25 | |
| 26 | else: |
Scott Baker | be8907d | 2014-02-05 09:25:44 -0800 | [diff] [blame] | 27 | def notify_observer(model=None, delete=False, pk=None, model_dict={}): |
Scott Baker | f1de7ea | 2014-02-05 09:27:50 -0800 | [diff] [blame] | 28 | global print_once |
Scott Baker | be8907d | 2014-02-05 09:25:44 -0800 | [diff] [blame] | 29 | if (print_once): |
| 30 | print "The observer is disabled" |
| 31 | print_once = False |
Sapan Bhatia | 9c2c8fa | 2013-10-16 13:26:05 -0400 | [diff] [blame] | 32 | return |