Reorganize build process
[mspang/pyceo.git] / pylib / csc / apps / urwid / positions.py
1 import urwid
2 from csc.apps.urwid.widgets import *
3 from csc.apps.urwid.window import *
4
5 from csc.adm import members
6 from csc.common.excep import InvalidArgument
7
8 position_data = [
9     ('president',       'President'),
10     ('vice-president',  'Vice-president'),
11     ('treasurer',       'Treasurer'),
12     ('secretary',       'Secretary'),
13     ('sysadmin',        'System Administrator'),
14     ('librarian',       'Librarian'),
15     ('imapd',           'Imapd'),
16     ('webmaster',       'Web Master'),
17 ]
18
19 class IntroPage(WizardPanel):
20     def init_widgets(self):
21         self.widgets = [
22             urwid.Text( "Managing Positions" ),
23             urwid.Divider(),
24             urwid.Text( "Enter a username for each position. If a position is "
25                         "held by multiple people, enter a comma-separated "
26                         "list of usernames. If a position is held by nobody "
27                         "leave the username blank." ),
28         ]
29     def focusable(self):
30         return False
31
32 class InfoPage(WizardPanel):
33     def init_widgets(self):
34         self.widgets = [
35             urwid.Text( "Positions" ),
36             urwid.Divider(),
37         ]
38         positions = members.list_positions()
39         self.position_widgets = {}
40         for (position, text) in position_data:
41             widget = WordEdit("%s: " % text)
42             if position in positions:
43                 widget.set_edit_text(','.join(positions[position].keys()))
44             else:
45                 widget.set_edit_text('')
46             self.position_widgets[position] = widget
47             self.widgets.append(widget)
48
49     def parse(self, entry):
50         if len(entry) == 0:
51             return []
52         return entry.split(',')
53
54     def check(self):
55         self.state['positions'] = {}
56         for (position, widget) in self.position_widgets.iteritems():
57             self.state['positions'][position] = \
58                 self.parse(widget.get_edit_text())
59             for p in self.state['positions'][position]:
60                 if members.get(p) == None:
61                     self.focus_widget(widget)
62                     set_status( "Invalid username: '%s'" % p )
63                     return True
64         clear_status()
65
66 class EndPage(WizardPanel):
67     def init_widgets(self):
68         old = members.list_positions()
69         self.headtext = urwid.Text("")
70         self.midtext = urwid.Text("")
71
72         self.widgets = [
73             self.headtext,
74             urwid.Divider(),
75             self.midtext,
76         ]
77     def focusable(self):
78         return False
79     def activate(self):
80         for (position, info) in self.state['positions'].iteritems():
81             members.set_position(position, info)
82         self.headtext.set_text("Positions Updated")
83         self.midtext.set_text("Congratulations, positions have been updated. "
84             "You should rebuild the website in order to update the Positions "
85             "page.")
86     def check(self):
87         pop_window()