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

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

fixes for files in custom

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