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

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

email and phone was not copied into application and personal after first login

  • Property svn:keywords set to Id
File size: 7.4 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 1781 2007-05-13 17:38:27Z 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        student_per = getattr(student,'personal',None)
47        if request.has_key('returning') and  student_app is None:
48            email=request.get("email")
49            phone=request.get("phone_nr")
50            context.waeup_tool.makeStudentData(str(member),
51                                                   email=email,
52                                                   phone_nr=phone,
53                                                   )
54            #d = {}
55            #d['id'] = str(member)
56            #d['email'] = email
57            #d['phone'] = phone
58            #context.students_catalog.modifyRecord(**d)
59        elif student_app is None:
60            context.waeup_tool.makeStudentData(str(member))
61        student_app = getattr(student,'application',None)
62        if 'payments' not in student.objectIds():
63            student.invokeFactory('PaymentsFolder','payments')
64            payments = getattr(student,'payments')
65            wftool.doActionFor(payments,'open')
66            d = {}
67            d['Title'] = 'Online Payments'
68            payments.getContent().edit(mapping=d)
69        student_pume = getattr(student,'pume',None)
70        s_review_state = wftool.getInfoFor(student,'review_state',None)
71        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
72        student_per = getattr(student,'personal',None)
73        p_review_state = wftool.getInfoFor(student_per,'review_state',None)
74        logger.info('%s logged in, review_state %s' % (member,s_review_state))
75        app_doc = student_app.getContent()
76       
77        if request.has_key('returning'):
78            email=request.get("email")
79            phone=request.get("phone_nr")       
80            # should be always closed, however ...
81            if a_review_state != 'opened':
82                wftool.doActionFor(student_app,'open')
83            # should be always opened after import, however ...
84            if p_review_state != 'opened':   
85                wftool.doActionFor(student_per,'open')
86            per_doc = student_per.getContent()
87            app_doc.edit(mapping = {'app_email' : email})
88            per_doc.edit(mapping = {'email' : email, 'phone' : phone})
89            wftool.doActionFor(student_app,'close')
90       
91        #from Products.zdb import set_trace;set_trace()
92        if load_passport and 'passport' not in app_doc.objectIds():
93            msg = context.waeup_tool.loadStudentFoto(student)
94            logger.info('%s, %s' % (member,msg))
95        if s_review_state in ("student_created","admitted") and\
96                             a_review_state == 'created' :
97            wftool.doActionFor(student_app,'open')
98            if student_pume is not None:
99              wftool.doActionFor(student_pume,'close')
100            da = {}
101            pin = request.get('pin')
102            if not 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['app_ac_pin'] = pin
115            da['app_ac_date'] = current
116            app_doc.edit(mapping = da)
117        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
118                                            not app_doc.app_ac_pin:
119            jamb_reg_no = app_doc.jamb_reg_no
120            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
121                res = context.portal_pins(student=reg_no)
122                if len(res) > 0:
123                    break
124            if len(res) > 0:
125                p = res[0].pin
126                if len(p) > 10:
127                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
128                else:
129                    pin = p
130                da = {}
131                da['app_ac_pin'] = pin
132                app_doc.edit(mapping = da)
133        elif s_review_state in ("cleared_and_validated",) and\
134                             p_review_state == 'created' :
135            wftool.doActionFor(student_per,'open')
136        res = context.students_catalog(id = str(member))
137        matric_no = res[0].matric_no
138        verdict = res[0].verdict
139        if s_review_state in ('returning','school_fee_paid') and not verdict:
140            results = context.results_import(matric_no = matric_no)
141            if results:
142                study_course = getattr(student,'study_course')
143                sc_review_state = wftool.getInfoFor(study_course,'review_state',None)
144                dsc = {}
145                dsc['current_verdict'] = context.getVerdict(results[0].Verdict)[0]
146                if sc_review_state != 'opened':
147                    wftool.doActionFor(study_course,'open')
148                study_course_doc =study_course.getContent()
149                study_course_doc.edit(mapping = dsc)
150                wftool.doActionFor(study_course,'close_for_edit')
151        has_results = context.results_import(matric_no = matric_no)
152        if s_review_state == "application_pin_entered":
153            redirect_url = "%s/application_edit_form" % student.absolute_url()
154        elif s_review_state in ('admitted', 'objection_raised',):
155            redirect_url = "%s/admission_form" % student.absolute_url()
156        elif s_review_state == "clearance_pin_entered":
157            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
158        elif s_review_state == "cleared_and_validated":
159            redirect_url = "%s/personal_edit_form" % student.absolute_url()
160        elif s_review_state == "returning" and has_results:
161            redirect_url = "%s/session_results_view" % student.absolute_url()
162        elif s_review_state in ('school_fee_paid','courses_registered'):
163            redirect_url = "%s/study_course/study_course_view" % student.absolute_url()
164        else:
165            redirect_url = "%s/student_index" % student.absolute_url()
166    else:
167        logger.info('%s logged in' % (member))
168        redirect_url = portal.absolute_url()
169#Anonymous
170else:
171    response.expireCookie('__ac', path='/')
172    return context.user_logged_in_failed()
173
174# Setup skins
175if (getattr(utool, 'updateSkinCookie', False) and
176    utool.updateSkinCookie()):
177    context.setupCurrentSkin()
178
179response.redirect(redirect_url)
180
Note: See TracBrowser for help on using the repository browser.