blob: 94dc37cd301c8177c9f6de88952ed0d5b7e545fd [file] [log] [blame]
Matteo Scandolof5e10332017-08-08 13:05:25 -07001
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 Bavier89a95422016-11-02 14:38:39 -040017from xos.config import Config
18
19try:
20 observer_disabled = Config().observer_disabled
21except:
22 observer_disabled = False
23
24def EnableObserver(x):
25 """ used for manage.py --noobserver """
26 global observer_disabled
27 observer_disabled = not x
28
29print_once = True
30
31def 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