blob: 91201260c46cafae948f8496f49b43911e4ca495 [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -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
Matteo Scandoloceccb1f2017-06-05 10:35:44 -070017# FIXME this file needs a refactoring
18observer_disabled = False
Scott Bakerb63ea792016-08-11 10:24:48 -070019
20def EnableObserver(x):
21 """ used for manage.py --noobserver """
22 global observer_disabled
23 observer_disabled = not x
24
25print_once = True
26
27def notify_observer(model=None, delete=False, pk=None, model_dict={}):
28 if (observer_disabled):
29 global print_once
30 if (print_once):
31 print "The observer is disabled"
32 print_once = False
33 return
34
35 try:
36 from .event_manager import EventSender
37 if (model and delete):
38 if hasattr(model,"__name__"):
39 modelName = model.__name__
40 else:
41 modelName = model.__class__.__name__
42 EventSender().fire(delete_flag = delete, model = modelName, pk = pk, model_dict=model_dict)
43 else:
44 EventSender().fire()
45 except Exception,e:
46 print "Exception in Observer. This should not disrupt the front end. %s"%str(e)
47
48