pyceo/ceo/urwid/positions.py

98 lines
3.3 KiB
Python
Raw Normal View History

2007-11-15 05:28:58 -05:00
import urwid
from ceo import members
from ceo.urwid.widgets import *
from ceo.urwid.window import *
2007-11-15 05:28:58 -05:00
position_data = [
('president', 'President'),
('vice-president', 'Vice-president'),
('treasurer', 'Treasurer'),
('secretary', 'Secretary'),
('sysadmin', 'System Administrator'),
2008-01-06 22:16:40 -05:00
('cro', 'Chief Returning Officer'),
2007-11-15 05:28:58 -05:00
('librarian', 'Librarian'),
('imapd', 'Imapd'),
('webmaster', 'Web Master'),
('offsck', 'Office Manager'),
2007-11-15 05:28:58 -05:00
]
class IntroPage(WizardPanel):
def init_widgets(self):
self.widgets = [
urwid.Text( "Managing Positions" ),
urwid.Divider(),
urwid.Text( "Enter a username for each position. If a position is "
"held by multiple people, enter a comma-separated "
"list of usernames. If a position is held by nobody "
"leave the username blank." ),
]
def focusable(self):
return False
class InfoPage(WizardPanel):
def init_widgets(self):
self.widgets = [
urwid.Text( "Positions" ),
urwid.Divider(),
]
positions = members.list_positions()
self.position_widgets = {}
for (position, text) in position_data:
2007-12-18 01:24:58 -05:00
widget = LdapWordEdit(csclub_uri, csclub_base, 'uid',
"%s: " % text)
2007-11-15 05:28:58 -05:00
if position in positions:
widget.set_edit_text(','.join(positions[position].keys()))
else:
widget.set_edit_text('')
self.position_widgets[position] = widget
self.widgets.append(widget)
def parse(self, entry):
if len(entry) == 0:
return []
return entry.split(',')
def check(self):
self.state['positions'] = {}
for (position, widget) in self.position_widgets.iteritems():
self.state['positions'][position] = \
self.parse(widget.get_edit_text())
for p in self.state['positions'][position]:
if members.get(p) == None:
self.focus_widget(widget)
set_status( "Invalid username: '%s'" % p )
return True
2007-11-15 05:28:58 -05:00
clear_status()
class EndPage(WizardPanel):
def init_widgets(self):
old = members.list_positions()
self.headtext = urwid.Text("")
self.midtext = urwid.Text("")
self.widgets = [
self.headtext,
urwid.Divider(),
self.midtext,
]
def focusable(self):
return False
def activate(self):
2007-12-18 01:49:13 -05:00
failed = []
2007-11-15 05:28:58 -05:00
for (position, info) in self.state['positions'].iteritems():
2007-12-18 01:49:13 -05:00
try:
members.set_position(position, info)
except ldap.LDAPError:
failed.append(position)
if len(failed) == 0:
self.headtext.set_text("Positions Updated")
self.midtext.set_text("Congratulations, positions have been "
"updated. You should rebuild the website in order to update "
"the Positions page.")
else:
self.headtext.set_text("Positions Results")
self.midtext.set_text("Failed to update the following positions: "
"%s." % join(failed))
2007-11-15 05:28:58 -05:00
def check(self):
pop_window()