Reorganize build process
[mspang/pyceo.git] / pylib / csc / apps / urwid / search.py
1 import urwid
2
3 from csc.apps.urwid.widgets import *
4 from csc.apps.urwid.window import *
5
6 from csc.adm import members, terms
7 from csc.common.excep import InvalidArgument
8
9 class TermPage(WizardPanel):
10     def init_widgets(self):
11         self.term = SingleEdit("Term: ")
12
13         self.widgets = [
14             urwid.Text( "Terms Members" ),
15             urwid.Divider(),
16             self.term,
17         ]
18     def check(self):
19         try:
20             self.state['term'] = self.term.get_edit_text()
21             terms.parse( self.state['term'] )
22         except:
23             self.focus_widget( self.term )
24             set_status( "Invalid term" )
25             return True
26         mlist = members.list_term( self.state['term'] ).values()
27         pop_window()
28         member_list( mlist )
29
30 class NamePage(WizardPanel):
31     def init_widgets(self):
32         self.name = SingleEdit("Name: ")
33
34         self.widgets = [
35             urwid.Text( "Members by Name" ),
36             urwid.Divider(),
37             self.name,
38         ]
39     def check(self):
40         self.state['name'] = self.name.get_edit_text()
41         if not self.state['name']:
42             self.focus_widget( self.name )
43             set_status( "Invalid name" )
44             return True
45         mlist = members.list_name( self.state['name'] ).values()
46         pop_window()
47         member_list( mlist )
48
49 class GroupPage(WizardPanel):
50     def init_widgets(self):
51         self.group = SingleEdit("Group: ")
52
53         self.widgets = [
54             urwid.Text( "Members by Group" ),
55             urwid.Divider(),
56             self.group,
57         ]
58     def check(self):
59         self.state['group'] = self.group.get_edit_text()
60         if not self.state['group']:
61             self.focus_widget( self.group )
62             set_status( "Invalid group" )
63             return True
64         mlist = members.list_group( self.state['group'] ).values()
65         pop_window()
66         member_list( mlist )
67
68 def member_list(mlist):
69     mlist = list(mlist)
70     mlist.sort( lambda x, y: cmp(x['uid'], y['uid']) )
71     buf = ''
72     for member in mlist:
73         if 'uid' in member:
74             uid = member['uid'][0]
75         else:
76             uid = None
77         if 'program' in member:
78             program = member['program'][0]
79         else:
80             program = None
81         attrs = ( uid, member['cn'][0], program )
82         buf += "%10s %30s\n%41s\n\n" % attrs
83     set_status("Press escape to return to the menu")
84     push_window(urwid.ListBox([urwid.Text(buf)]))
85
86