blob: 5d5db61a5f03587347ce91776118b371fd33146e [file] [log] [blame]
srikanth116e6e82014-08-19 07:22:37 -07001#
2# Copyright (c) 2013 Big Switch Networks, Inc.
3#
4# Licensed under the Eclipse Public License, Version 1.0 (the
5# "License"); you may not use this file except in compliance with the
6# License. You may obtain a copy of the License at
7#
8# http://www.eclipse.org/legal/epl-v10.html
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
13# implied. See the License for the specific language governing
14# permissions and limitations under the License.
15#
16
17from django.db import models
18from django.conf.urls.defaults import *
19
20# This is a class that is used to keep a list of apps and their tabs in memory
21class AppLister():
22
23 def __init__(self, name, label, priority, description=""):
24 self.name = name
25 self.label = label
26 self.priority = priority
27 self.description = description
28 self.tabs = []
29
30 def orderTabs(self, a, b):
31 return cmp(int(a["priority"]), int(b["priority"]))
32
33 def addTab(self, id, label, view, priority=1000):
34 for t in self.tabs:
35 if t["id"] == id:
36 self.tabs.remove(t)
37 self.tabs.append( { 'id':id, 'label':label, "priority":priority, "view":view } )
38 self.tabs.sort(self.orderTabs)
39
40class AppLoader():
41
42 # List of all registered applications
43 #
44 # This is a list of dictionaries
45 #
46
47 firstInit = True
48 apps = []
49
50 @classmethod
51 def orderApps(cls, a, b):
52 return cmp(int(a.priority), int(b.priority))
53
54 @classmethod
55 def addApp(cls,app):
56 for a in cls.apps:
57 if a.name == app.name:
58 return False
59 cls.apps.append(app)
60 cls.apps.sort(cls.orderApps)
61
62 @classmethod
63 def getApps(cls):
64 return cls.apps
65
66 @classmethod
67 def getApp(cls, name):
68 for a in cls.apps:
69 if a.name == name:
70 return a
71 return None
72
73 @classmethod
74 def registerAllApps(cls):
75 if cls.firstInit:
76 from django.conf import settings
77 if "sdncon.coreui" not in settings.INSTALLED_APPS:
78 print "****** panic, sdncon.coreui is missing!"
79 for app in settings.INSTALLED_APPS:
80 if not app.startswith("django"):
81 init_func = __import__("%s.views" % app, fromlist=["bsc_app_init"])
82 if 'bsc_app_init' in dir(init_func):
83 init_func.bsc_app_init()
84 cls.firstInit=False