Silence pychecker and pylint warnings
[public/pyceo-broken.git] / pylib / csc / apps / urwid / newmember.py
1 import urwid
2 from csc.apps.urwid.widgets import *
3 from csc.apps.urwid.window import *
4
5 from csc.adm import accounts, members, terms
6 from csc.common.excep import InvalidArgument
7
8 class IntroPage(WizardPanel):
9     def init_widgets(self):
10         self.widgets = [
11             urwid.Text( "Joining the Computer Science Club" ),
12             urwid.Divider(),
13             urwid.Text( "CSC membership is $2.00 for one term. Please ensure "
14                         "the fee is deposited into the safe before continuing." ),
15         ]
16     def focusable(self):
17         return False
18
19 class ClubIntroPage(WizardPanel):
20     def init_widgets(self):
21         self.widgets = [
22             urwid.Text( "Club Services" ),
23             urwid.Divider(),
24             urwid.Text( "We provide other UW clubs accounts for email and "
25                         "web hosting, free of charge. Like members, clubs "
26                         "get web hosting at %s. We can also arrange for "
27                         "uwaterloo.ca subdomains; please instruct the club "
28                         "representative to contact the systems committee "
29                         "for more information."
30                         "\n\nNote: This is not complete. Authorizing members "
31                         "to access the club account still requires manual "
32                         "intervention."
33                         % "http://csclub.uwaterloo.ca/~clubid/"
34             )
35         ]
36     def focusable(self):
37         return False
38
39 class InfoPage(WizardPanel):
40     def init_widgets(self):
41         self.userid = LdapFilterWordEdit("UWuserid: ")
42         self.name = SingleEdit("Full name: ")
43         self.program = SingleEdit("Program of Study: ")
44         self.userid.set_ldap_filter(
45             "ldap://uwldap.uwaterloo.ca/", "dc=uwaterloo,dc=ca",
46             "uid", {'cn':self.name, 'ou':self.program}
47         )
48         self.widgets = [
49             urwid.Text( "Member Information - Please Check ID" ),
50             urwid.Divider(),
51             self.userid,
52             self.name,
53             self.program,
54         ]
55     def check(self):
56         self.state['userid'] = self.userid.get_edit_text()
57         self.state['name'] = self.name.get_edit_text()
58         self.state['program'] = self.program.get_edit_text()
59
60         if len( self.state['userid'] ) < 3:
61             self.focus_widget( self.userid )
62             set_status("Username is too short")
63             return True
64         elif len( self.state['name'] ) < 4:
65             self.focus_widget( self.name )
66             set_status("Name is too short")
67             return True
68         clear_status()
69
70 class ClubInfoPage(WizardPanel):
71     def init_widgets(self):
72         self.userid = WordEdit("Username: ")
73         self.name = SingleEdit("Club Name: ")
74         self.widgets = [
75             urwid.Text( "Club Information" ),
76             urwid.Divider(),
77             self.userid,
78             self.name,
79         ]
80     def check(self):
81         self.state['userid'] = self.userid.get_edit_text()
82         self.state['name'] = self.name.get_edit_text()
83
84         if len( self.state['userid'] ) < 3:
85             self.focus_widget( self.userid )
86             set_status("Username is too short")
87             return True
88         elif len( self.state['name'] ) < 4:
89             self.focus_widget( self.name )
90             set_status("Name is too short")
91             return True
92         clear_status()
93
94 class SignPage(WizardPanel):
95     def init_widgets(self):
96         self.widgets = [
97             urwid.Text( "Machine Usage Policy" ),
98             urwid.Divider(),
99             urwid.Text( "Ensure the new member has signed the "
100                         "Machine Usage Policy. Accounts of users who have not "
101                         "signed will be suspended if discovered." ),
102         ]
103     def focusable(self):
104         return False
105
106 class PassPage(WizardPanel):
107     def init_widgets(self):
108         self.password = PassEdit("Password: ")
109         self.pwcheck = PassEdit("Re-enter: ")
110         self.widgets = [
111             urwid.Text( "Member Password" ),
112             urwid.Divider(),
113             self.password,
114             self.pwcheck,
115         ]
116     def focus_widget(self, widget):
117         self.box.set_focus( self.widgets.index( widget ) )
118     def clear_password(self):
119         self.focus_widget( self.password )
120         self.password.set_edit_text("")
121         self.pwcheck.set_edit_text("")
122     def check(self):
123         self.state['password'] = self.password.get_edit_text()
124         pwcheck = self.pwcheck.get_edit_text()
125
126         if self.state['password'] != pwcheck:
127             self.clear_password()
128             set_status("Passwords do not match")
129             return True
130         elif len(self.state['password']) < 5:
131             self.clear_password()
132             set_status("Password is too short")
133             return True
134         clear_status()
135
136 class EndPage(WizardPanel):
137     def __init__(self, state, utype='member'):
138         self.type = utype
139         WizardPanel.__init__(self, state)
140     def init_widgets(self):
141         self.headtext = urwid.Text("")
142         self.midtext = urwid.Text("")
143         self.widgets = [
144             self.headtext,
145             urwid.Divider(),
146             self.midtext,
147         ]
148     def focusable(self):
149         return False
150     def check(self):
151         pop_window()
152     def activate(self):
153         problem = None
154         try:
155             if self.type == 'member':
156                 accounts.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'] )
157                 members.register( self.state['userid'], terms.current() )
158             elif self.type == 'club':
159                 accounts.create_club( self.state['userid'], self.state['name'] )
160             else:
161                 raise Exception("Internal Error")
162         except accounts.NameConflict, e:
163             problem = str(e)
164         except accounts.NoAvailableIDs, e:
165             problem = str(e)
166         except accounts.InvalidArgument, e:
167             problem = str(e)
168         except accounts.LDAPException, e:
169             problem = str(e)
170         except accounts.KrbException, e:
171             problem = str(e)
172         except accounts.ChildFailed, e:
173             problem = str(e)
174
175         if problem:
176             self.headtext.set_text("Failures Occured Adding User")
177             self.midtext.set_text("The error was:\n%s\nThe account may be partially added "
178                 "and you may or may not be able to log in. Please contact systems committee." % problem)
179             return
180         else:
181             self.headtext.set_text("User Added")
182             self.midtext.set_text("Congratulations, %s has been added "
183                 "successfully. You should also rebuild the website in "
184                 "order to update the memberlist."
185                 % self.state['userid'])