Re-build so debian.csclub include library as a dependency
[public/pyceo-broken.git] / ceo / urwid / positions.py
1 import urwid
2 from ceo import members
3 from ceo.urwid.widgets import *
4 from ceo.urwid.window import *
5
6 position_data = [
7     ('president',       'President'),
8     ('vice-president',  'Vice-president'),
9     ('treasurer',       'Treasurer'),
10     ('secretary',       'Secretary'),
11     ('sysadmin',        'System Administrator'),
12     ('cro',             'Chief Returning Officer'),
13     ('librarian',       'Librarian'),
14     ('imapd',           'Imapd'),
15     ('webmaster',       'Web Master'),
16     ('offsck',          'Office Manager'),
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 = LdapWordEdit(csclub_uri, csclub_base, 'uid',
42                 "%s: " % text)
43             if position in positions:
44                 widget.set_edit_text(','.join(positions[position].keys()))
45             else:
46                 widget.set_edit_text('')
47             self.position_widgets[position] = widget
48             self.widgets.append(widget)
49
50     def parse(self, entry):
51         if len(entry) == 0:
52             return []
53         return entry.split(',')
54
55     def check(self):
56         self.state['positions'] = {}
57         for (position, widget) in self.position_widgets.iteritems():
58             self.state['positions'][position] = \
59                 self.parse(widget.get_edit_text())
60             for p in self.state['positions'][position]:
61                 if members.get(p) == None:
62                     self.focus_widget(widget)
63                     set_status( "Invalid username: '%s'" % p )
64                     return True
65         clear_status()
66
67 class EndPage(WizardPanel):
68     def init_widgets(self):
69         old = members.list_positions()
70         self.headtext = urwid.Text("")
71         self.midtext = urwid.Text("")
72
73         self.widgets = [
74             self.headtext,
75             urwid.Divider(),
76             self.midtext,
77         ]
78     def focusable(self):
79         return False
80     def activate(self):
81         failed = []
82         for (position, info) in self.state['positions'].iteritems():
83             try:
84                 members.set_position(position, info)
85             except ldap.LDAPError:
86                 failed.append(position)
87         if len(failed) == 0:
88             self.headtext.set_text("Positions Updated")
89             self.midtext.set_text("Congratulations, positions have been "
90                 "updated. You should rebuild the website in order to update "
91                 "the Positions page.")
92         else:
93             self.headtext.set_text("Positions Results")
94             self.midtext.set_text("Failed to update the following positions: "
95                 "%s." % join(failed))
96     def check(self):
97         pop_window()