source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_custom/logged_in.py @ 11110

Last change on this file since 11110 was 1933, checked in by Henrik Bettermann, 17 years ago

is that correct?

(it's still not active)

  • Property svn:keywords set to Id
File size: 8.0 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 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()
38#load_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 = context.getStudentReviewState(student.id)
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 s_review_state == 'returning' and 'passport' not in app_doc.objectIds():
93            folder = 'pictures_returning'
94            res = context.students_catalog(id = str(member))
95            filename = res[0].matric_no.upper()
96            msg = context.waeup_tool.loadStudentFoto(student,filename,folder)
97            logger.info('%s (%s), %s' % (member,s_review_state,msg))
98        if s_review_state in ('admitted', 'clearance_pin_entered', 'clearance_requested')  and 'passport' not in app_doc.objectIds():
99            folder = 'pictures_admitted_latest'
100            filename = app_doc.jamb_reg_no.replace('/','_')
101            msg = context.waeup_tool.loadStudentFoto(student,filename,folder)
102            logger.info('%s (%s), %s' % (member,s_review_state,msg))
103        if s_review_state in ("student_created","admitted") and\
104                             a_review_state == 'created' :
105            wftool.doActionFor(student_app,'open')
106            if student_pume is not None:
107              wftool.doActionFor(student_pume,'close')
108            da = {}
109            pin = request.get('pin')
110            if not pin:
111                jamb_reg_no = app_doc.jamb_reg_no
112                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
113                    res = context.portal_pins(student=reg_no)
114                    if len(res) > 0:
115                        break
116                if len(res) > 0:
117                    p = res[0].pin
118                    if len(p) > 10:
119                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
120                    else:
121                        pin = p
122            da['app_ac_pin'] = pin
123            da['app_ac_date'] = current
124            app_doc.edit(mapping = da)
125        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
126                                            not app_doc.app_ac_pin:
127            jamb_reg_no = app_doc.jamb_reg_no
128            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
129                res = context.portal_pins(student=reg_no)
130                if len(res) > 0:
131                    break
132            if len(res) > 0:
133                p = res[0].pin
134                if len(p) > 10:
135                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
136                else:
137                    pin = p
138                da = {}
139                da['app_ac_pin'] = pin
140                app_doc.edit(mapping = da)
141        elif s_review_state in ("cleared_and_validated",) and\
142                             p_review_state == 'created' :
143            wftool.doActionFor(student_per,'open')
144        res = context.students_catalog(id = str(member))
145        matric_no = res[0].matric_no
146        verdict = res[0].verdict
147        if s_review_state in ('returning','school_fee_paid') and not verdict:
148            results = context.results_import(matric_no = matric_no)
149            if results:
150                study_course = getattr(student,'study_course')
151                sc_review_state = wftool.getInfoFor(study_course,'review_state',None)
152                dsc = {}
153                dsc['current_verdict'] = context.getVerdict(results[0].Verdict)[0]
154                if sc_review_state != 'opened':
155                    wftool.doActionFor(study_course,'open')
156                study_course_doc =study_course.getContent()
157                study_course_doc.edit(mapping = dsc)
158                wftool.doActionFor(study_course,'close_for_edit')
159        has_results = context.results_import(matric_no = matric_no)
160        if s_review_state == "application_pin_entered":
161            redirect_url = "%s/application_edit_form" % student.absolute_url()
162        elif s_review_state in ('admitted', 'objection_raised',):
163            redirect_url = "%s/admission_form" % student.absolute_url()
164        elif s_review_state == "clearance_pin_entered":
165            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
166        elif s_review_state == "cleared_and_validated":
167            redirect_url = "%s/personal_edit_form" % student.absolute_url()
168        elif s_review_state == "returning" and has_results:
169            redirect_url = "%s/session_results_view" % student.absolute_url()
170        elif s_review_state in ('school_fee_paid','courses_registered'):
171            redirect_url = "%s/study_course/study_course_view" % student.absolute_url()
172        else:
173            redirect_url = "%s/student_index" % student.absolute_url()
174    else:
175        logger.info('%s logged in' % (member))
176        redirect_url = portal.absolute_url()
177#Anonymous
178else:
179    response.expireCookie('__ac', path='/')
180    return context.user_logged_in_failed()
181
182# Setup skins
183if (getattr(utool, 'updateSkinCookie', False) and
184    utool.updateSkinCookie()):
185    context.setupCurrentSkin()
186
187response.redirect(redirect_url)
188
Note: See TracBrowser for help on using the repository browser.