source: WAeUP_SRP/branches/uli/skins/waeup_custom/logged_in.py @ 2157

Last change on this file since 2157 was 1593, checked in by uli, 18 years ago

Merged current trunk into uli-branch.

  • Property svn:keywords set to Id
File size: 5.8 KB
RevLine 
[1346]1## Script (Python) "logged_in"
[524]2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[1092]7##parameters=
[524]8##title=
9##
10"""Prepare user login
11modified from cps_default/logged_in.py
12
[805]13$Id: logged_in.py 1593 2007-03-19 18:57:54Z uli $
[524]14"""
[1487]15try:
16    from Products.zdb import set_trace
17except:
18    def set_trace():
19        pass
[535]20import DateTime
21current = DateTime.DateTime()
[1004]22import logging
[1593]23logger = logging.getLogger('Skins.logged_in')
[524]24
[1004]25
[524]26from urllib import unquote
27
[535]28request = context.REQUEST
29response = request.RESPONSE
[524]30utool = context.portal_url
31mtool = context.portal_membership
[551]32wftool = context.portal_workflow
[524]33portal = utool.getPortalObject()
34
35redirect_to_portal = False
36is_anon = mtool.isAnonymousUser()
37member = mtool.getAuthenticatedMember()
[1285]38load_passport = hasattr(context.waeup_tool,'loadStudentFoto')
[524]39
[1092]40if 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))
[1228]45        student_app = getattr(student,'application',None)
46        if request.has_key('returning') and student_app is None:
[1215]47            email=request.get("email")
48            phone=request.get("phone_nr")
[1158]49            context.waeup_tool.makeStudentData(str(member),
[1215]50                                               email=email,
51                                               phone_nr=phone,
[1158]52                                               )
[1215]53            d = {}
54            d['id'] = str(member)
55            d['email'] = email
56            d['phone'] = phone
57            context.students_catalog.modifyRecord(**d)
[1231]58        elif student_app is None:
[1151]59            context.waeup_tool.makeStudentData(str(member))
60        student_app = getattr(student,'application',None)
[1241]61        if 'payments' not in student.objectIds():
62            student.invokeFactory('PaymentsFolder','payments')
63            payments = getattr(student,'payments')
[1242]64            wftool.doActionFor(payments,'open')
[1241]65            d = {}
66            d['Title'] = 'Online Payments'
67            payments.getContent().edit(mapping=d)
[1092]68        student_pume = getattr(student,'pume',None)
69        s_review_state = wftool.getInfoFor(student,'review_state',None)
70        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
[1347]71        student_per = getattr(student,'personal',None)
72        p_review_state = wftool.getInfoFor(student_per,'review_state',None)
[1593]73        logger.info('%s logged in, review_state %s' % (member,s_review_state))
[1092]74        app_doc = student_app.getContent()
[1285]75        #from Products.zdb import set_trace;set_trace()
76        if load_passport and 'passport' not in app_doc.objectIds():
77            msg = context.waeup_tool.loadStudentFoto(student)
[1593]78            logger.info('%s, %s' % (member,msg))
[1092]79        if s_review_state in ("student_created","admitted") and\
[1096]80                             a_review_state == 'created' :
[1092]81            wftool.doActionFor(student_app,'open')
82            if student_pume is not None:
83              wftool.doActionFor(student_pume,'close')
84            da = {}
85            pin = request.get('pin')
86            if not pin:
[999]87                jamb_reg_no = app_doc.jamb_reg_no
88                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
89                    res = context.portal_pins(student=reg_no)
90                    if len(res) > 0:
91                        break
92                if len(res) > 0:
93                    p = res[0].pin
94                    if len(p) > 10:
95                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
96                    else:
97                        pin = p
[1092]98            da['app_ac_pin'] = pin
99            da['app_ac_date'] = current
100            app_doc.edit(mapping = da)
101        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
[1096]102                                            not app_doc.app_ac_pin:
[1092]103            jamb_reg_no = app_doc.jamb_reg_no
104            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
105                res = context.portal_pins(student=reg_no)
106                if len(res) > 0:
107                    break
108            if len(res) > 0:
109                p = res[0].pin
110                if len(p) > 10:
111                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
112                else:
113                    pin = p
114                da = {}
115                da['app_ac_pin'] = pin
116                app_doc.edit(mapping = da)
[1347]117        elif s_review_state in ("cleared_and_validated",) and\
118                             p_review_state == 'created' :
119            wftool.doActionFor(student_per,'open')
[1417]120        res = context.students_catalog(id = str(member))
121        matric_no = res[0].matric_no
122        is_imported = context.returning_import(matric_no = matric_no)
[1092]123        if s_review_state == "application_pin_entered":
[1344]124            redirect_url = "%s/application_edit_form" % student.absolute_url()
[1092]125        elif s_review_state in ('admitted', 'objection_raised',):
[1094]126            redirect_url = "%s/admission_form" % student.absolute_url()
[1092]127        elif s_review_state == "clearance_pin_entered":
[1094]128            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
[1347]129        elif s_review_state == "cleared_and_validated":
130            redirect_url = "%s/personal_edit_form" % student.absolute_url()
[1417]131        elif s_review_state == "returning" and is_imported:
[1174]132            redirect_url = "%s/session_results_view" % student.absolute_url()
[1096]133        else:
134            redirect_url = "%s/student_index" % student.absolute_url()
[1092]135    else:
[1593]136        logger.info('%s logged in' % (member))
[1094]137        redirect_url = portal.absolute_url()
138#Anonymous
[1092]139else:
140    response.expireCookie('__ac', path='/')
[524]141    return context.user_logged_in_failed()
142
[1094]143# Setup skins
144if (getattr(utool, 'updateSkinCookie', False) and
145    utool.updateSkinCookie()):
146    context.setupCurrentSkin()
[524]147
[1094]148response.redirect(redirect_url)
149
Note: See TracBrowser for help on using the repository browser.