source: WAeUP_SRP/branches/srpp_on_branch/skins/waeup_custom/logged_in.py @ 3736

Last change on this file since 3736 was 1285, checked in by joachim, 18 years ago

upload passport foto during login for returning students.
filename of foto is matric_no.jpg in import/pictures_returning

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
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 1285 2007-01-12 16:04:40Z joachim $
14"""
15import DateTime
16current = DateTime.DateTime()
17import logging
18logger = logging.getLogger('Member.Login')
19
20
21from urllib import unquote
22
23request = context.REQUEST
24response = request.RESPONSE
25utool = context.portal_url
26mtool = context.portal_membership
27wftool = context.portal_workflow
28portal = utool.getPortalObject()
29
30redirect_to_portal = False
31is_anon = mtool.isAnonymousUser()
32member = mtool.getAuthenticatedMember()
33load_passport = hasattr(context.waeup_tool,'loadStudentFoto')
34
35if not is_anon:
36    if "Student" in member.getRoles():
37        to_waeup_student_home = True
38        students = context.portal_url.getPortalObject().campus.students
39        student = getattr(students,str(member))
40        student_app = getattr(student,'application',None)
41        if request.has_key('returning') and student_app is None:
42            email=request.get("email")
43            phone=request.get("phone_nr")
44            context.waeup_tool.makeStudentData(str(member),
45                                               email=email,
46                                               phone_nr=phone,
47                                               )
48            d = {}
49            d['id'] = str(member)
50            d['email'] = email
51            d['phone'] = phone
52            context.students_catalog.modifyRecord(**d)
53        elif student_app is None:
54            context.waeup_tool.makeStudentData(str(member))
55        student_app = getattr(student,'application',None)
56        if 'payments' not in student.objectIds():
57            student.invokeFactory('PaymentsFolder','payments')
58            payments = getattr(student,'payments')
59            wftool.doActionFor(payments,'open')
60            d = {}
61            d['Title'] = 'Online Payments'
62            payments.getContent().edit(mapping=d)
63        student_pume = getattr(student,'pume',None)
64        s_review_state = wftool.getInfoFor(student,'review_state',None)
65        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
66        logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state))
67        app_doc = student_app.getContent()
68        #from Products.zdb import set_trace;set_trace()
69        if load_passport and 'passport' not in app_doc.objectIds():
70            msg = context.waeup_tool.loadStudentFoto(student)
71            logger.info('"%s", "%s"' % (member,msg))
72        if s_review_state in ("student_created","admitted") and\
73                             a_review_state == 'created' :
74            wftool.doActionFor(student_app,'open')
75            if student_pume is not None:
76              wftool.doActionFor(student_pume,'close')
77            da = {}
78            pin = request.get('pin')
79            if not pin:
80                jamb_reg_no = app_doc.jamb_reg_no
81                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
82                    res = context.portal_pins(student=reg_no)
83                    if len(res) > 0:
84                        break
85                if len(res) > 0:
86                    p = res[0].pin
87                    if len(p) > 10:
88                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
89                    else:
90                        pin = p
91            da['app_ac_pin'] = pin
92            da['app_ac_date'] = current
93            app_doc.edit(mapping = da)
94        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
95                                            not app_doc.app_ac_pin:
96            jamb_reg_no = app_doc.jamb_reg_no
97            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
98                res = context.portal_pins(student=reg_no)
99                if len(res) > 0:
100                    break
101            if len(res) > 0:
102                p = res[0].pin
103                if len(p) > 10:
104                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
105                else:
106                    pin = p
107                da = {}
108                da['app_ac_pin'] = pin
109                app_doc.edit(mapping = da)
110        if s_review_state == "application_pin_entered":
111            rdirect_url = "%s/application_edit_form" % student.absolute_url()
112        elif s_review_state in ('admitted', 'objection_raised',):
113            redirect_url = "%s/admission_form" % student.absolute_url()
114        elif s_review_state == "clearance_pin_entered":
115            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
116        if s_review_state == "returning":
117            redirect_url = "%s/session_results_view" % student.absolute_url()
118        else:
119            redirect_url = "%s/student_index" % student.absolute_url()
120    else:
121        logger.info('"%s", "logged in"' % (member))
122        redirect_url = portal.absolute_url()
123#Anonymous
124else:
125    response.expireCookie('__ac', path='/')
126    return context.user_logged_in_failed()
127
128# Setup skins
129if (getattr(utool, 'updateSkinCookie', False) and
130    utool.updateSkinCookie()):
131    context.setupCurrentSkin()
132
133response.redirect(redirect_url)
134
Note: See TracBrowser for help on using the repository browser.