]> git.openstreetmap.org Git - osqa.git/blob - forum/modules/ui.py
OSQA-828, Support fullname to real_name mapping from OpenID providers
[osqa.git] / forum / modules / ui.py
1
2
3 class Registry(list):
4     def add(self, item):
5         for i, r in enumerate(self):
6             if r.weight > item.weight:
7                 self.insert(i, item)
8                 return
9
10         self.append(item)
11
12     def find_by_name(self, name):
13         for i in self:
14             if i.name and (i.name == name):
15                 return i
16
17     def remove_by_name(self, name):
18         for i, r in enumerate(self):
19             if r.name and (r.name == name):
20                 return self.pop(i)
21
22
23 HEAD_CONTENT = 'HEAD_CONTENT'
24 HEADER_LINKS = 'HEADER_LINKS'
25 PAGE_TOP_TABS = 'PAGE_TOP_TABS'
26 FOOTER_LINKS = 'FOOTER_LINKS'
27 PROFILE_TABS = 'PROFILE_TABS'
28
29 USER_MENU = 'USER_MENU'
30
31
32 __CONTAINER = {
33     HEAD_CONTENT: Registry(),
34     HEADER_LINKS: Registry(),
35     PAGE_TOP_TABS: Registry(),
36     FOOTER_LINKS: Registry(),
37     PROFILE_TABS: Registry(),
38
39     USER_MENU: Registry(),
40 }
41
42
43 def register(registry, *ui_objects):
44     if not registry in __CONTAINER:
45         raise('unknown registry')
46
47     for ui_object in ui_objects:
48         __CONTAINER[registry].add(ui_object)
49
50 def get_registry_by_name(name):
51     name = name.upper()
52
53     if not name in __CONTAINER:
54         raise('unknown registry')
55
56     return __CONTAINER[name]
57
58
59
60 from ui_objects import *
61