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