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

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

Ziwschenversion

Ich arbeite noch an layout_application_edit.pt

File size: 11.1 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 == "student_created":
152            wftool.doActionFor(student,'admit')
153            s_review_state = 'admitted'       
154
155        if s_review_state == "admitted" and a_review_state == 'created':
156            wftool.doActionFor(student_app,'open')
157            #if student_pume is not None:
158            #  wftool.doActionFor(student_pume,'close')
159            da = {}
160            pin = request.get('pin')
161
162            # if the student comes directly, add missing pin or pin with wrong syntax (fix)
163            if not pin:
164                jamb_reg_no = app_doc.jamb_reg_no
165                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
166                    res = context.portal_pins(student=reg_no)
167                    if len(res) > 0:
168                        break
169                if len(res) > 0:
170                    p = res[0].pin
171                    if len(p) > 10:
172                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
173                    else:
174                        pin = p
175            da['app_ac_pin'] = pin
176            da['app_ac_date'] = current
177            app_doc.edit(mapping = da)
178
179        # 2. same as 1 but without opening app_doc, assuming that the student already logged in
180        #    but the pin is missing in app_doc (fix)
181
182        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
183                                            not app_doc.app_ac_pin:
184            jamb_reg_no = app_doc.jamb_reg_no
185            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
186                res = context.portal_pins(student=reg_no)
187                if len(res) > 0:
188                    break
189            if len(res) > 0:
190                p = res[0].pin
191                if len(p) > 10:
192                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
193                else:
194                    pin = p
195                da = {}
196                da['app_ac_pin'] = pin
197                app_doc.edit(mapping = da)
198
199        # 3. open personal object (fix). This should be done in clearance_edit.
200
201        elif s_review_state in ("cleared_and_validated",) and\
202                             p_review_state == 'created' :
203            wftool.doActionFor(student_per,'open')
204
205        #########################################################
206
207        res = context.students_catalog(id = str(member))
208        matric_no = res[0].matric_no
209        verdict = res[0].verdict
210        level = res[0].level
211        has_level = level
212        has_verdict = verdict and not verdict == 'N/A'
213        #set_trace()
214
215        #########################################################
216
217        if matric_no:
218            has_results = context.results_import(matric_no = matric_no)
219        else:
220            has_results = ''
221
222        #########################################################
223
224        # fetch current verdict via getVerdict and level via getLevelFromResultsCosCode
225
226        if s_review_state in ('returning','school_fee_paid') and not (has_verdict and has_level):
227            if has_results:
228                study_course = getattr(student,'study_course')
229                sc_review_state = wftool.getInfoFor(study_course,'review_state',None)
230                dsc = {}
231                if not has_verdict and s_review_state == 'returning':
232                    dsc['current_verdict'] = context.getVerdict(has_results[0].Verdict)[0]
233                if not has_level and s_review_state == 'returning':
234                    lnr = context.getLevelFromResultsCosCode(has_results)
235                    dsc['current_level'] = "%d00" % lnr
236                elif not has_level and s_review_state == 'school_fee_paid':
237                    lnr = context.getLevelFromResultsCosCode(has_results)
238                    cv = context.getVerdict(has_results[0].Verdict)[0]
239                    if cv in ('A','B',):
240                        lnr += 1
241                    dsc['current_level'] = "%d00" % lnr
242                    dsc['previous_verdict'] = cv
243                if sc_review_state != 'opened':
244                    wftool.doActionFor(study_course,'open')
245                study_course_doc =study_course.getContent()
246                study_course_doc.edit(mapping = dsc)
247                wftool.doActionFor(study_course,'close_for_edit')
248
249        #########################################################
250
251
252        # determine appropriate redirect url
253
254        if s_review_state == "application_pin_entered":
255            redirect_url = "%s/application_edit_form" % student.absolute_url()
256        elif s_review_state in ('admitted', 'objection_raised',):
257            redirect_url = "%s/admission_form" % student.absolute_url()
258        elif s_review_state == "clearance_pin_entered":
259            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
260        elif s_review_state == "cleared_and_validated":
261            redirect_url = "%s/personal_edit_form" % student.absolute_url()
262        elif s_review_state == "returning" and has_results:
263            redirect_url = "%s/session_results_view" % student.absolute_url()
264        elif s_review_state in ('school_fee_paid','courses_registered'):
265            redirect_url = "%s/study_course/study_course_view" % student.absolute_url()
266        else:
267            redirect_url = "%s/student_index" % student.absolute_url()
268
269
270    else:
271        logger.info('%s logged in' % (member))
272        redirect_url = portal.absolute_url()
273#Anonymous
274else:
275    response.expireCookie('__ac', path='/')
276    return context.user_logged_in_failed()
277
278# Setup skins
279if (getattr(utool, 'updateSkinCookie', False) and
280    utool.updateSkinCookie()):
281    context.setupCurrentSkin()
282
283response.redirect(redirect_url)
284
Note: See TracBrowser for help on using the repository browser.