Reorganize build process
[mspang/pyceo.git] / pylib / csc / apps / urwid / renew.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
8 class IntroPage(WizardPanel):
9     def init_widgets(self):
10         self.widgets = [
11             urwid.Text( "Renewing Membership" ),
12             urwid.Divider(),
13             urwid.Text( "CSC membership is $2.00 per term. You may pre-register "
14                         "for future terms if desired." )
15         ]
16     def focusable(self):
17         return False
18
19 class UserPage(WizardPanel):
20     def init_widgets(self):
21         self.userid = WordEdit("Username: ")
22
23         self.widgets = [
24             urwid.Text( "Member Information" ),
25             urwid.Divider(),
26             self.userid,
27         ]
28     def check(self):
29         self.state['userid'] = self.userid.get_edit_text()
30         self.state['member'] = None
31         if self.state['userid']:
32             self.state['member'] = members.get(self.userid.get_edit_text())
33         if not self.state['member']:
34             set_status("Member not found")
35             self.focus_widget(self.userid)
36             return True
37
38 class TermPage(WizardPanel):
39     def init_widgets(self):
40         self.start = SingleEdit("Start: ")
41         self.count = SingleIntEdit("Count: ")
42
43         self.widgets = [
44             urwid.Text( "Terms to Register" ),
45             urwid.Divider(),
46             self.start,
47             self.count,
48         ]
49     def activate(self):
50         if not self.start.get_edit_text():
51             old_terms = []
52             if 'term' in self.state['member']:
53                 old_terms = self.state['member']['term']
54             self.start.set_edit_text( terms.next_unregistered( old_terms ) )
55             self.count.set_edit_text( "1" )
56     def check(self):
57         try:
58             self.state['terms'] = terms.interval( self.start.get_edit_text(), self.count.value() )
59         except Exception, e:
60             self.focus_widget( self.start )
61             set_status( "Invalid start term" )
62             return True
63         for term in self.state['terms']:
64             if members.registered( self.state['userid'], term):
65                 self.focus_widget( self.start )
66                 set_status( "Already registered for " + term )
67                 return True
68         if len(self.state['terms']) == 0:
69             self.focus_widget(self.count)
70             set_status( "Registering for zero terms?" )
71             return True
72
73 class PayPage(WizardPanel):
74     def init_widgets(self):
75         self.midtext = urwid.Text("")
76
77         self.widgets = [
78             urwid.Text("Membership Fee"),
79             urwid.Divider(),
80             self.midtext,
81         ]
82     def focusable(self):
83         return False
84     def activate(self):
85         regterms = self.state['terms']
86         plural = "term"
87         if len(self.state['terms']) > 1:
88             plural = "terms"
89         self.midtext.set_text("You are registering for %d %s, and owe the "
90                        "Computer Science Club $%d.00 in membership fees. "
91                        "Please deposit the money in the safe before "
92                        "continuing. " % ( len(regterms), plural, len(regterms * 2)))
93
94 class EndPage(WizardPanel):
95     def init_widgets(self):
96         self.headtext = urwid.Text("")
97         self.midtext = urwid.Text("")
98
99         self.widgets = [
100             self.headtext,
101             urwid.Divider(),
102             self.midtext,
103         ]
104     def focusable(self):
105         return False
106     def activate(self):
107         try:
108             members.register( self.state['userid'], self.state['terms'] )
109             self.headtext.set_text("Registration Succeeded")
110             self.midtext.set_text("The member has been registered for the following "
111                              "terms: " + ", ".join(self.state['terms']) + ".")
112         except Exception, e:
113             self.headtext.set_text("Failed to Register")
114             self.midtext.set_text("You may refund any fees paid or retry."
115                              "The error was: '%s'" % e)
116     def check(self):
117         pop_window()