Matteo Scandolo | f5e1033 | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 17 | from xos.config import Config |
| 18 | |
| 19 | try: |
| 20 | observer_disabled = Config().observer_disabled |
| 21 | except: |
| 22 | observer_disabled = False |
| 23 | |
| 24 | def EnableObserver(x): |
| 25 | """ used for manage.py --noobserver """ |
| 26 | global observer_disabled |
| 27 | observer_disabled = not x |
| 28 | |
| 29 | print_once = True |
| 30 | |
| 31 | def notify_observer(model=None, delete=False, pk=None, model_dict={}): |
| 32 | if (observer_disabled): |
| 33 | global print_once |
| 34 | if (print_once): |
| 35 | print "The observer is disabled" |
| 36 | print_once = False |
| 37 | return |
| 38 | |
| 39 | try: |
| 40 | from .event_manager import EventSender |
| 41 | if (model and delete): |
| 42 | if hasattr(model,"__name__"): |
| 43 | modelName = model.__name__ |
| 44 | else: |
| 45 | modelName = model.__class__.__name__ |
| 46 | EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict) |
| 47 | else: |
| 48 | EventSender().fire() |
| 49 | except Exception,e: |
| 50 | print "Exception in Observer. This should not disrupt the front end. %s"%str(e) |
| 51 | |
| 52 | |