source: WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py @ 1620

Last change on this file since 1620 was 1568, checked in by Henrik Bettermann, 18 years ago

new logging format Part 3

  • Property svn:keywords set to Id
File size: 5.8 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 1568 2007-03-17 08:37:51Z 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()
38load_passport = hasattr(context.waeup_tool,'loadStudentFoto')
39
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))
45        student_app = getattr(student,'application',None)
46        if request.has_key('returning') and student_app is None:
47            email=request.get("email")
48            phone=request.get("phone_nr")
49            context.waeup_tool.makeStudentData(str(member),
50                                               email=email,
51                                               phone_nr=phone,
52                                               )
53            d = {}
54            d['id'] = str(member)
55            d['email'] = email
56            d['phone'] = phone
57            context.students_catalog.modifyRecord(**d)
58        elif student_app is None:
59            context.waeup_tool.makeStudentData(str(member))
60        student_app = getattr(student,'application',None)
61        if 'payments' not in student.objectIds():
62            student.invokeFactory('PaymentsFolder','payments')
63            payments = getattr(student,'payments')
64            wftool.doActionFor(payments,'open')
65            d = {}
66            d['Title'] = 'Online Payments'
67            payments.getContent().edit(mapping=d)
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)
71        student_per = getattr(student,'personal',None)
72        p_review_state = wftool.getInfoFor(student_per,'review_state',None)
73        logger.info('%s logged in, review_state %s' % (member,s_review_state))
74        app_doc = student_app.getContent()
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)
78            logger.info('%s, %s' % (member,msg))
79        if s_review_state in ("student_created","admitted") and\
80                             a_review_state == 'created' :
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:
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
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\
102                                            not app_doc.app_ac_pin:
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)
117        elif s_review_state in ("cleared_and_validated",) and\
118                             p_review_state == 'created' :
119            wftool.doActionFor(student_per,'open')
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)
123        if s_review_state == "application_pin_entered":
124            redirect_url = "%s/application_edit_form" % student.absolute_url()
125        elif s_review_state in ('admitted', 'objection_raised',):
126            redirect_url = "%s/admission_form" % student.absolute_url()
127        elif s_review_state == "clearance_pin_entered":
128            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
129        elif s_review_state == "cleared_and_validated":
130            redirect_url = "%s/personal_edit_form" % student.absolute_url()
131        elif s_review_state == "returning" and is_imported:
132            redirect_url = "%s/session_results_view" % student.absolute_url()
133        else:
134            redirect_url = "%s/student_index" % student.absolute_url()
135    else:
136        logger.info('%s logged in' % (member))
137        redirect_url = portal.absolute_url()
138#Anonymous
139else:
140    response.expireCookie('__ac', path='/')
141    return context.user_logged_in_failed()
142
143# Setup skins
144if (getattr(utool, 'updateSkinCookie', False) and
145    utool.updateSkinCookie()):
146    context.setupCurrentSkin()
147
148response.redirect(redirect_url)
149
Note: See TracBrowser for help on using the repository browser.