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

Last change on this file since 999 was 999, checked in by joachim, 18 years ago

edit app_ac_pin if not set (logged_in.py)
set default to all states (search students)

  • Property svn:keywords set to Id
File size: 5.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=came_from=None
8##title=
9##
10"""Prepare user login
11modified from cps_default/logged_in.py
12
13$Id: logged_in.py 999 2006-12-06 10:46:32Z joachim $
14"""
15import DateTime
16current = DateTime.DateTime()
17
18from urllib import unquote
19
20def checkRedirect(portal, mtool):
21    to_member_home = False
22    to_workspaces = False
23##    has_home = mtool.getHomeFolder()
24##    if has_home:
25##        to_member_home = True
26##    if not has_home and mtool.checkPermission('View', portal.workspaces):
27##        to_workspaces = True
28    return to_member_home, to_workspaces
29
30request = context.REQUEST
31response = request.RESPONSE
32utool = context.portal_url
33mtool = context.portal_membership
34wftool = context.portal_workflow
35portal = utool.getPortalObject()
36portal_absolute_url = portal.absolute_url()
37
38redirect_url = came_from
39redirect_to_portal = False
40to_member_home = False
41to_workspaces = False
42to_waeup_student_home = False
43
44is_anon = mtool.isAnonymousUser()
45member = mtool.getAuthenticatedMember()
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')
53        student_pume = getattr(student,'pume',None)
54        s_review_state = wftool.getInfoFor(student,'review_state',None)
55        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
56        app_doc = student_app.getContent()
57        #from Products.zdb import set_trace
58        #set_trace()
59        if s_review_state in ("student_created","admitted") and\
60        a_review_state == 'created' :
61            wftool.doActionFor(student_app,'open')
62            if student_pume is not None:
63              wftool.doActionFor(student_pume,'close')
64            da = {}
65            pin = request.get('pin')
66            if not pin:
67                jamb_reg_no = app_doc.jamb_reg_no
68                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
69                    res = context.portal_pins(student=reg_no)
70                    if len(res) > 0:
71                        break
72                if len(res) > 0:
73                    p = res[0].pin
74                    if len(p) > 10:
75                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
76                    else:
77                        pin = p
78            da['app_ac_pin'] = pin
79            da['app_ac_date'] = current
80            app_doc.edit(mapping = da)
81        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
82        not app_doc.app_ac_pin:
83            jamb_reg_no = app_doc.jamb_reg_no
84            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
85                res = context.portal_pins(student=reg_no)
86                if len(res) > 0:
87                    break
88            if len(res) > 0:
89                p = res[0].pin
90                if len(p) > 10:
91                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
92                else:
93                    pin = p
94                da = {}
95                da['app_ac_pin'] = pin
96                app_doc.edit(mapping = da)
97    elif "Manager" in member.getRoles():
98        pass
99    else:
100        to_member_home, to_workspaces = checkRedirect(portal, mtool)
101if (not to_member_home) and (not to_workspaces):
102    redirect_to_portal = True
103
104if to_waeup_student_home:
105    #member.setProperties(last_login_time=current,login_time=current)
106    #if info['review_state'] == "application_pin_entered":
107    if s_review_state == "application_pin_entered":
108        return response.redirect("%s/application_edit" % student.absolute_url())
109    #elif info['review_state'] == "admitted":
110    elif s_review_state == "admitted":
111        return response.redirect("%s/admission_form" % student.absolute_url())
112    #elif info['review_state'] == "clearance_pin_entered":
113    elif s_review_state == "clearance_pin_entered":
114        return response.redirect("%s/clearance_edit" % student.absolute_url())
115    return response.redirect("%s/student_index" % student.absolute_url())
116
117elif to_member_home:
118    redirect_url = mtool.getHomeFolder().absolute_url()
119elif to_workspaces:
120    redirect_url = portal.workspaces.absolute_url()
121elif redirect_to_portal:
122    redirect_url = portal_absolute_url
123
124REQUEST = context.REQUEST
125RESPONSE = REQUEST.RESPONSE
126
127# Setup skins
128if (getattr(utool, 'updateSkinCookie', False) and
129    utool.updateSkinCookie()):
130    context.setupCurrentSkin()
131
132# Anonymous
133if is_anon:
134    RESPONSE.expireCookie('__ac', path='/')
135    return context.user_logged_in_failed()
136
137login_time = member.getProperty('login_time', '2000/01/01')
138first_time = (str(login_time) == '2000/01/01')
139
140##if first_time and member.has_role('Member') and not member.has_role('Student'):
141##    mtool.createMemberArea()
142##    now = context.ZopeTime()
143##    member.setProperties(last_login_time=now, login_time=now)
144
145if to_member_home or to_workspaces:
146    redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in')
147RESPONSE.redirect(redirect_url)
Note: See TracBrowser for help on using the repository browser.