source: WAeUP_SRP/trunk/skins/waeup_fceokene/logged_in.py @ 17959

Last change on this file since 17959 was 3865, checked in by Henrik Bettermann, 16 years ago
  • fix sort order of payment objects
  • reload passport pictures in Okene
File size: 10.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 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
39if context.isStaff():
40    is_unsecure = context.waeup_tool.checkGenericPassword(str(member))
41    if is_unsecure:
42        response.expireCookie('__ac', path='/')
43        return response.redirect("%s/user_logged_in_disabled" % context.portal_url())
44
45#load_passport = hasattr(context.waeup_tool,'loadStudentFoto')
46
47if not is_anon:
48    if "Student" in member.getRoles():
49        to_waeup_student_home = True
50        students = context.portal_url.getPortalObject().campus.students
51        student = getattr(students,str(member))
52        student_app = getattr(student,'application',None)
53        student_per = getattr(student,'personal',None)
54
55        #########################################################
56
57        # perform makeStudentData for returning students who login for the first time
58        # the returning key comes from set_access_data
59
60        if request.has_key('returning') and  student_per is None:
61            email=request.get("email")
62            phone=request.get("phone_nr")
63            context.waeup_tool.makeStudentData(str(member),
64                                                   email=email,
65                                                   phone_nr=phone,
66                                                   )
67            #d = {}
68            #d['id'] = str(member)
69            #d['email'] = email
70            #d['phone'] = phone
71            #context.students_catalog.modifyRecord(**d)
72        elif student_per is None:
73            context.waeup_tool.makeStudentData(str(member))
74
75        #########################################################
76
77        student_app = getattr(student,'application',None)
78
79        #########################################################
80
81        # add missing payments folder
82
83        if 'payments' not in student.objectIds():
84            student.invokeFactory('PaymentsFolder','payments')
85            payments = getattr(student,'payments')
86            wftool.doActionFor(payments,'open')
87            d = {}
88            d['Title'] = 'Online Payments'
89            payments.getContent().edit(mapping=d)
90
91        #########################################################
92
93        #student_pume = getattr(student,'pume',None)
94        s_review_state = context.getStudentReviewState(student.id)
95        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
96        student_per = getattr(student,'personal',None)
97        p_review_state = wftool.getInfoFor(student_per,'review_state',None)
98        logger.info('%s logged in, review_state %s' % (member,s_review_state))
99        if student_app is None:
100            logger.info('%s logged in, without application object' % (member))
101        else:
102            app_doc = student_app.getContent()
103
104        #########################################################
105
106        # save email and phone of returning students after all objects have been created
107
108        if request.has_key('returning') and student_app:
109            email=request.get("email")
110            phone=request.get("phone_nr")
111            # should be always closed, however ...
112            if a_review_state != 'opened':
113                wftool.doActionFor(student_app,'open')
114            # should be always opened after import, however ...
115            if p_review_state != 'opened':
116                wftool.doActionFor(student_per,'open')
117            per_doc = student_per.getContent()
118            app_doc.edit(mapping = {'app_email' : email})
119            per_doc.edit(mapping = {'email' : email, 'phone' : phone})
120            wftool.doActionFor(student_app,'close')
121
122        #########################################################
123
124        # look for passport pictures
125        student_id = student.getId()
126        if not context.waeup_tool.picturesExist(('passport',), student_id):
127            folder = 'images/reload'
128            msg = context.waeup_tool.loadStudentFoto(student,student_id,folder)
129            logger.info('%s (%s), %s' % (student_id,s_review_state,msg))
130
131
132        #########################################################
133
134        # perform necessary updates for new students
135
136        # 1. add pin and application date to app_doc
137
138        if s_review_state == "student_created":
139            wftool.doActionFor(student,'admit')
140            s_review_state = 'admitted'
141
142        if s_review_state == "admitted" and a_review_state == 'created':
143            wftool.doActionFor(student_app,'open')
144            #if student_pume is not None:
145            #  wftool.doActionFor(student_pume,'close')
146            da = {}
147            pin = request.get('pin')
148
149            # if the student comes directly, add missing pin or pin with wrong syntax (fix)
150            if not pin:
151                jamb_reg_no = app_doc.jamb_reg_no
152                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
153                    res = context.portal_pins(student=reg_no)
154                    if len(res) > 0:
155                        break
156                if len(res) > 0:
157                    p = res[0].pin
158                    if len(p) > 10:
159                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
160                    else:
161                        pin = p
162            da['app_ac_pin'] = pin
163            da['app_ac_date'] = current
164            app_doc.edit(mapping = da)
165
166        # 2. same as 1 but without opening app_doc, assuming that the student already logged in
167        #    but the pin is missing in app_doc (fix)
168
169        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
170                                            not app_doc.app_ac_pin:
171            jamb_reg_no = app_doc.jamb_reg_no
172            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
173                res = context.portal_pins(student=reg_no)
174                if len(res) > 0:
175                    break
176            if len(res) > 0:
177                p = res[0].pin
178                if len(p) > 10:
179                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
180                else:
181                    pin = p
182                da = {}
183                da['app_ac_pin'] = pin
184                app_doc.edit(mapping = da)
185
186        # 3. open personal object (fix). This should be done in clearance_edit.
187
188        elif s_review_state in ("cleared_and_validated",) and\
189                             p_review_state == 'created' :
190            wftool.doActionFor(student_per,'open')
191
192        #########################################################
193
194        res = context.students_catalog(id = str(member))
195        matric_no = res[0].matric_no
196        verdict = res[0].verdict
197        level = res[0].level
198        has_level = level
199        has_verdict = verdict and not verdict == 'N/A'
200        #set_trace()
201
202        #########################################################
203
204        if matric_no:
205            has_results = context.results_import(matric_no = matric_no)
206        else:
207            has_results = ''
208
209        #########################################################
210
211        # fetch current verdict via getVerdict and level via getLevelFromResultsCosCode
212
213        if s_review_state in ('returning','school_fee_paid') and not (has_verdict and has_level):
214            if has_results:
215                study_course = getattr(student,'study_course')
216                sc_review_state = wftool.getInfoFor(study_course,'review_state',None)
217                dsc = {}
218                if not has_verdict and s_review_state == 'returning':
219                    dsc['current_verdict'] = context.getVerdict(has_results[0].Verdict)[0]
220                if not has_level and s_review_state == 'returning':
221                    lnr = context.getLevelFromResultsCosCode(has_results)
222                    dsc['current_level'] = "%d00" % lnr
223                elif not has_level and s_review_state == 'school_fee_paid':
224                    lnr = context.getLevelFromResultsCosCode(has_results)
225                    cv = context.getVerdict(has_results[0].Verdict)[0]
226                    if cv in ('A','B',):
227                        lnr += 1
228                    dsc['current_level'] = "%d00" % lnr
229                    dsc['previous_verdict'] = cv
230                if sc_review_state != 'opened':
231                    wftool.doActionFor(study_course,'open')
232                study_course_doc =study_course.getContent()
233                study_course_doc.edit(mapping = dsc)
234                wftool.doActionFor(study_course,'close_for_edit')
235
236        #########################################################
237
238
239        # determine appropriate redirect url
240
241        if s_review_state == "application_pin_entered":
242            redirect_url = "%s/application_edit_form" % student.absolute_url()
243        elif s_review_state in ('admitted', 'objection_raised',):
244            redirect_url = "%s/admission_form" % student.absolute_url()
245        elif s_review_state == "clearance_pin_entered":
246            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
247        elif s_review_state == "cleared_and_validated":
248            redirect_url = "%s/personal_edit_form" % student.absolute_url()
249        elif s_review_state == "returning" and has_results:
250            redirect_url = "%s/session_results_view" % student.absolute_url()
251        elif s_review_state in ('school_fee_paid','courses_registered'):
252            redirect_url = "%s/study_course/study_course_view" % student.absolute_url()
253        else:
254            redirect_url = "%s/student_index" % student.absolute_url()
255
256
257    else:
258        logger.info('%s logged in' % (member))
259        redirect_url = portal.absolute_url()
260#Anonymous
261else:
262    response.expireCookie('__ac', path='/')
263    return context.user_logged_in_failed()
264
265# Setup skins
266if (getattr(utool, 'updateSkinCookie', False) and
267    utool.updateSkinCookie()):
268    context.setupCurrentSkin()
269
270response.redirect(redirect_url)
271
Note: See TracBrowser for help on using the repository browser.