1 | ## Script (Python) "logged_in" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | """Prepare user login |
---|
11 | modified from cps_default/logged_in.py |
---|
12 | |
---|
13 | $Id: logged_in.py 1933 2007-06-19 05:05:29Z henrik $ |
---|
14 | """ |
---|
15 | try: |
---|
16 | from Products.zdb import set_trace |
---|
17 | except: |
---|
18 | def set_trace(): |
---|
19 | pass |
---|
20 | import DateTime |
---|
21 | current = DateTime.DateTime() |
---|
22 | import logging |
---|
23 | logger = logging.getLogger('Skins.logged_in') |
---|
24 | |
---|
25 | |
---|
26 | from urllib import unquote |
---|
27 | |
---|
28 | request = context.REQUEST |
---|
29 | response = request.RESPONSE |
---|
30 | utool = context.portal_url |
---|
31 | mtool = context.portal_membership |
---|
32 | wftool = context.portal_workflow |
---|
33 | portal = utool.getPortalObject() |
---|
34 | |
---|
35 | redirect_to_portal = False |
---|
36 | is_anon = mtool.isAnonymousUser() |
---|
37 | member = mtool.getAuthenticatedMember() |
---|
38 | #load_passport = hasattr(context.waeup_tool,'loadStudentFoto') |
---|
39 | |
---|
40 | if not is_anon: |
---|
41 | if "Student" in member.getRoles(): |
---|
42 | to_waeup_student_home = True |
---|
43 | students = context.portal_url.getPortalObject().campus.students |
---|
44 | student = getattr(students,str(member)) |
---|
45 | student_app = getattr(student,'application',None) |
---|
46 | student_per = getattr(student,'personal',None) |
---|
47 | |
---|
48 | ######################################################### |
---|
49 | |
---|
50 | # perform makeStudentData for returning students who login for the first time |
---|
51 | # the returning key comes from set_access_data |
---|
52 | |
---|
53 | if request.has_key('returning') and student_app is None: |
---|
54 | email=request.get("email") |
---|
55 | phone=request.get("phone_nr") |
---|
56 | context.waeup_tool.makeStudentData(str(member), |
---|
57 | email=email, |
---|
58 | phone_nr=phone, |
---|
59 | ) |
---|
60 | #d = {} |
---|
61 | #d['id'] = str(member) |
---|
62 | #d['email'] = email |
---|
63 | #d['phone'] = phone |
---|
64 | #context.students_catalog.modifyRecord(**d) |
---|
65 | elif student_app is None: |
---|
66 | context.waeup_tool.makeStudentData(str(member)) |
---|
67 | |
---|
68 | ######################################################### |
---|
69 | |
---|
70 | student_app = getattr(student,'application',None) |
---|
71 | |
---|
72 | ######################################################### |
---|
73 | |
---|
74 | # add missing payments folder |
---|
75 | |
---|
76 | if 'payments' not in student.objectIds(): |
---|
77 | student.invokeFactory('PaymentsFolder','payments') |
---|
78 | payments = getattr(student,'payments') |
---|
79 | wftool.doActionFor(payments,'open') |
---|
80 | d = {} |
---|
81 | d['Title'] = 'Online Payments' |
---|
82 | payments.getContent().edit(mapping=d) |
---|
83 | |
---|
84 | ######################################################### |
---|
85 | |
---|
86 | #student_pume = getattr(student,'pume',None) |
---|
87 | s_review_state = context.getStudentReviewState(student.id) |
---|
88 | a_review_state = wftool.getInfoFor(student_app,'review_state',None) |
---|
89 | student_per = getattr(student,'personal',None) |
---|
90 | p_review_state = wftool.getInfoFor(student_per,'review_state',None) |
---|
91 | logger.info('%s logged in, review_state %s' % (member,s_review_state)) |
---|
92 | app_doc = student_app.getContent() |
---|
93 | |
---|
94 | ######################################################### |
---|
95 | |
---|
96 | # save email and phone of returning students after all objects have been created |
---|
97 | |
---|
98 | if request.has_key('returning'): |
---|
99 | email=request.get("email") |
---|
100 | phone=request.get("phone_nr") |
---|
101 | # should be always closed, however ... |
---|
102 | if a_review_state != 'opened': |
---|
103 | wftool.doActionFor(student_app,'open') |
---|
104 | # should be always opened after import, however ... |
---|
105 | if p_review_state != 'opened': |
---|
106 | wftool.doActionFor(student_per,'open') |
---|
107 | per_doc = student_per.getContent() |
---|
108 | app_doc.edit(mapping = {'app_email' : email}) |
---|
109 | per_doc.edit(mapping = {'email' : email, 'phone' : phone}) |
---|
110 | wftool.doActionFor(student_app,'close') |
---|
111 | |
---|
112 | ######################################################### |
---|
113 | |
---|
114 | # look for passport pictures of returning students |
---|
115 | |
---|
116 | #if s_review_state == 'returning' and 'passport' not in app_doc.objectIds(): |
---|
117 | # use new test |
---|
118 | if s_review_state == 'returning' and\ |
---|
119 | not context.waeup_tool.picturesExist(('passport',), student.getId()): |
---|
120 | folder = 'pictures_returning' |
---|
121 | res = context.students_catalog(id = str(member)) |
---|
122 | filename = res[0].matric_no.upper() |
---|
123 | msg = context.waeup_tool.loadStudentFoto(student,filename,folder) |
---|
124 | logger.info('%s (%s), %s' % (member,s_review_state,msg)) |
---|
125 | |
---|
126 | |
---|
127 | ######################################################### |
---|
128 | |
---|
129 | # look for passport pictures of new students |
---|
130 | |
---|
131 | if s_review_state in ('admitted', |
---|
132 | 'clearance_pin_entered', |
---|
133 | 'clearance_requested' |
---|
134 | ) and not context.waeup_tool.picturesExist(('passport',), |
---|
135 | student.getId()): |
---|
136 | folder = 'pictures_admitted_latest' |
---|
137 | filename = app_doc.jamb_reg_no.replace('/','_') |
---|
138 | msg = context.waeup_tool.loadStudentFoto(student,filename,folder) |
---|
139 | logger.info('%s (%s), %s' % (member,s_review_state,msg)) |
---|
140 | |
---|
141 | |
---|
142 | ######################################################### |
---|
143 | |
---|
144 | # perform necessary updates for new students |
---|
145 | |
---|
146 | # 1. add pin and application date to app_doc |
---|
147 | |
---|
148 | if s_review_state in ("student_created","admitted") and\ |
---|
149 | a_review_state == 'created' : |
---|
150 | wftool.doActionFor(student_app,'open') |
---|
151 | #if student_pume is not None: |
---|
152 | # wftool.doActionFor(student_pume,'close') |
---|
153 | da = {} |
---|
154 | pin = request.get('pin') |
---|
155 | |
---|
156 | # if the student comes directly, add missing pin or pin with wrong syntax (fix) |
---|
157 | if not pin: |
---|
158 | jamb_reg_no = app_doc.jamb_reg_no |
---|
159 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
160 | res = context.portal_pins(student=reg_no) |
---|
161 | if len(res) > 0: |
---|
162 | break |
---|
163 | if len(res) > 0: |
---|
164 | p = res[0].pin |
---|
165 | if len(p) > 10: |
---|
166 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
167 | else: |
---|
168 | pin = p |
---|
169 | da['app_ac_pin'] = pin |
---|
170 | da['app_ac_date'] = current |
---|
171 | app_doc.edit(mapping = da) |
---|
172 | |
---|
173 | # 2. same as 1 but without opening app_doc, assuming that the student already logged in |
---|
174 | # but the pin is missing in app_doc (fix) |
---|
175 | |
---|
176 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
177 | not app_doc.app_ac_pin: |
---|
178 | jamb_reg_no = app_doc.jamb_reg_no |
---|
179 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
180 | res = context.portal_pins(student=reg_no) |
---|
181 | if len(res) > 0: |
---|
182 | break |
---|
183 | if len(res) > 0: |
---|
184 | p = res[0].pin |
---|
185 | if len(p) > 10: |
---|
186 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
187 | else: |
---|
188 | pin = p |
---|
189 | da = {} |
---|
190 | da['app_ac_pin'] = pin |
---|
191 | app_doc.edit(mapping = da) |
---|
192 | |
---|
193 | # 3. open personal object (fix). This should be done in clearance_edit. |
---|
194 | |
---|
195 | elif s_review_state in ("cleared_and_validated",) and\ |
---|
196 | p_review_state == 'created' : |
---|
197 | wftool.doActionFor(student_per,'open') |
---|
198 | |
---|
199 | ######################################################### |
---|
200 | |
---|
201 | res = context.students_catalog(id = str(member)) |
---|
202 | matric_no = res[0].matric_no |
---|
203 | verdict = res[0].verdict |
---|
204 | level = res[0].level |
---|
205 | has_level = level |
---|
206 | has_verdict = verdict and not verdict == 'N/A' |
---|
207 | #set_trace() |
---|
208 | |
---|
209 | ######################################################### |
---|
210 | |
---|
211 | has_results = context.results_import(matric_no = matric_no) |
---|
212 | |
---|
213 | ######################################################### |
---|
214 | |
---|
215 | # fetch current verdict via getVerdict and level via getLevelFromResultsCosCode |
---|
216 | |
---|
217 | if s_review_state in ('returning','school_fee_paid') and not (has_verdict and has_level): |
---|
218 | if has_results: |
---|
219 | study_course = getattr(student,'study_course') |
---|
220 | sc_review_state = wftool.getInfoFor(study_course,'review_state',None) |
---|
221 | dsc = {} |
---|
222 | if not has_verdict: |
---|
223 | dsc['current_verdict'] = context.getVerdict(has_results[0].Verdict)[0] |
---|
224 | if not has_level and s_review_state == 'returning': |
---|
225 | lnr = context.getLevelFromResultsCosCode(has_results) |
---|
226 | dsc['current_level'] = "%d00" % lnr |
---|
227 | elif not has_level and s_review_state == 'school_fee_paid': |
---|
228 | lnr = context.getLevelFromResultsCosCode(has_results) |
---|
229 | if dsc['current_verdict'] in ('A','B',): |
---|
230 | lnr += 1 |
---|
231 | dsc['current_level'] = "%d00" % lnr |
---|
232 | if sc_review_state != 'opened': |
---|
233 | wftool.doActionFor(study_course,'open') |
---|
234 | study_course_doc =study_course.getContent() |
---|
235 | study_course_doc.edit(mapping = dsc) |
---|
236 | wftool.doActionFor(study_course,'close_for_edit') |
---|
237 | |
---|
238 | ######################################################### |
---|
239 | |
---|
240 | |
---|
241 | # determine appropriate redirect url |
---|
242 | |
---|
243 | if s_review_state == "application_pin_entered": |
---|
244 | redirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
245 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
246 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
247 | elif s_review_state == "clearance_pin_entered": |
---|
248 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
249 | elif s_review_state == "cleared_and_validated": |
---|
250 | redirect_url = "%s/personal_edit_form" % student.absolute_url() |
---|
251 | elif s_review_state == "returning" and has_results: |
---|
252 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
253 | elif s_review_state in ('school_fee_paid','courses_registered'): |
---|
254 | redirect_url = "%s/study_course/study_course_view" % student.absolute_url() |
---|
255 | else: |
---|
256 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
257 | |
---|
258 | |
---|
259 | else: |
---|
260 | logger.info('%s logged in' % (member)) |
---|
261 | redirect_url = portal.absolute_url() |
---|
262 | #Anonymous |
---|
263 | else: |
---|
264 | response.expireCookie('__ac', path='/') |
---|
265 | return context.user_logged_in_failed() |
---|
266 | |
---|
267 | # Setup skins |
---|
268 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
269 | utool.updateSkinCookie()): |
---|
270 | context.setupCurrentSkin() |
---|
271 | |
---|
272 | response.redirect(redirect_url) |
---|
273 | |
---|