-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditGroups.py
76 lines (61 loc) · 2.34 KB
/
EditGroups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
"""Menu for editing CDR groups.
"""
from functools import cached_property
from cdrcgi import Controller
class Control(Controller):
"""Encapsulates processing logic for building the menu page."""
SUBTITLE = "Manage Groups"
LOGNAME = "ManageGroups"
ADD_NEW_GROUP = "Add New Group"
EDIT_GROUP = "EditGroup.py"
def run(self):
"""Override base class to add action for new button."""
if self.request == self.ADD_NEW_GROUP:
self.navigate_to(self.EDIT_GROUP, self.session.name)
else:
Controller.run(self)
def populate_form(self, page):
"""Add group editing links to the page."""
page.body.set("class", "admin-menu")
fieldset = page.fieldset("Existing Groups (click to edit)")
fieldset.set("id", "group-list")
script = self.EDIT_GROUP
ul = page.B.UL()
for group in self.session.list_groups():
link = page.menu_link(script, group, grp=group)
if not self.deleted and not self.returned:
link.set("target", "_blank")
ul.append(page.B.LI(link))
fieldset.append(ul)
page.form.append(fieldset)
page.add_css("""
#group-list ul { list-style-type: none; column-width: 15rem; }
#group-list a { text-decoration: none; }
""")
@cached_property
def alerts(self):
"""Let the user know if we successfully deleted an action."""
if self.deleted:
message = f"Successfully deleted group {self.deleted!r}."
return [dict(message=message, type="success")]
return []
@property
def buttons(self):
"""Override to specify custom button for this page."""
return [self.ADD_NEW_GROUP]
@cached_property
def deleted(self):
"""Name of group which was just deleted, if appropriate."""
return self.fields.getvalue("deleted")
@cached_property
def returned(self):
"""True if user clicked the Group Menu button on the editing form."""
return True if self.fields.getvalue("returned") else False
@cached_property
def same_window(self):
"""Don't multiply browser tabs recursively."""
return self.buttons if self.deleted or self.returned else []
if __name__ == "__main__":
"""Don't execute the script if loaded as a module."""
Control().run()