source: WAeUP_SRP/trunk/skins/cps_custom/logged_in.py @ 5506

Last change on this file since 5506 was 5506, checked in by Henrik Bettermann, 14 years ago

logged_in.py: do not fill app_mobile after first_time_login

apply_admission_manage.py: hand over reg_no after psm == 'invalid'

clean application_edit_form.pt

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