source: WAeUP_SRP/base/skins/cps_custom/logged_in.py @ 2492

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

fix for students with strange session result course codes
beautify course result views
create_level.py: do not fill grade of carry-over courses; grade is a deprecated catalog field

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