source: WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py @ 1014

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

check for IndexError?

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1## Script (Python) "getStudentInfo"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=student=None
8##title=
9##
10# $Id: getStudentInfo.py 1007 2006-12-07 18:37:06Z joachim $
11"""
12return Info about the current Student
13"""
14request = context.REQUEST
15form = request.form
16fget = form.get
17wf = context.portal_workflow
18mtool = context.portal_membership
19member = mtool.getAuthenticatedMember()
20path_info = request.get('PATH_INFO').split('/')
21
22import logging
23logger = logging.getLogger('getStudentInfo')
24
25info = {}
26member_id = str(member)
27#from Products.zdb import set_trace
28#set_trace()
29student_id = None
30if student is None:
31    while True:
32        if mtool.isAnonymousUser():
33            return None
34        try:
35            requested_id = path_info[path_info.index('students')+1]
36        except ValueError:
37            student_id = member_id
38            break
39        except IndexError:
40            student_id = member_id
41            break
42        if not context.isStudent() and 'students' in path_info:
43            student_id = requested_id
44            break
45        if member_id != requested_id:
46            logger.info("Student %s tried to access %s" % (member_id,requested_id))
47            student_id = member_id
48            #mtool.assertViewable(context)
49            break
50        student_id = member_id
51        break
52else:
53    student_id = student.getId()
54
55roles = member.getRoles()
56student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
57student = context.restrictedTraverse(student_path,default=None)
58
59if student is None or student.portal_type != "Student":
60    return None
61##res = context.portal_catalog(id = student_id,portal_type='Student')
62##if not res:# or len(res) > 1:
63##    return None
64##brain = res[-1]
65##student = brain.getObject()
66info['review_state'] = wf.getInfoFor(student,'review_state',None)
67info['student'] = student
68info['id'] = student.getId()
69info['url'] = student.absolute_url()
70info['student_doc'] = student.getContent()
71info['app'] = student.application
72info['app_doc'] = student.application.getContent()
73info['per'] = getattr(student,'personal',None)
74info['sex'] = 'male'
75if info['per'] is not None:
76    info['per_doc'] = student.personal.getContent()
77    if info['per_doc'].sex:
78        info['sex'] = 'female'
79else:
80    if info['app_doc'].jamb_sex == "F":
81        info['sex'] = 'female'
82course = getattr(student,'study_course',None)
83info['course'] = course
84if course:
85    info['course_doc'] = student.study_course.getContent()
86#
87acco = getattr(student,'accommodation_2006',None)
88info['acco'] = acco
89if acco is not None:
90    info['acco_doc'] = acco.getContent()
91    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
92#
93clear = getattr(student,'clearance',None)
94info['clear'] = clear
95if clear is not None:
96    info['clear_doc'] = clear.getContent()
97    info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None)
98#
99pume = getattr(student,'pume',None)
100info['pume'] = pume
101if pume is not None:
102    info['pume_doc'] = pume.getContent()
103    info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None)
104else:
105    info['pume'] = None
106
107items = []
108s_edit_links = {'StudentApplication': 'application_edit_form',
109              'StudentAccommodation': 'reserve_accommodation',
110              'StudentClearance': 'clearance_edit_form',
111              'StudentPersonal': '',
112              }
113s_view_links = {'StudentApplication': 'application_view',
114              'StudentAccommodation': 'accommodation_view',
115              'StudentClearance': 'clearance_view',
116              'StudentPersonal': None,
117              'StudentStudyCourse': 'study_course_view',
118              'StudentPume': 'pume_view',
119              }
120sos = context.portal_catalog(container_path=student_path)
121for so in sos:
122    row = {}
123    soo = so.getObject()
124    sod = soo.getContent()
125    row['id'] = soo.getId()
126    row['title'] = sod.Title()
127    row['url'] = soo.absolute_url()
128    row['type'] = so.portal_type
129    row['is_editable'] = mtool.checkPermission('Modify portal content', soo)
130    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
131    row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link)
132    se_link = s_edit_links.get(so.portal_type,None)
133    row['s_edit_link'] = None
134    if se_link:
135        row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link)
136    row['review_state'] = so.review_state
137    row['display'] = so.review_state in ('opened','closed',)
138    items.append(row)
139info['items'] = items
140request.set('student_id',student_id)
141request.set('student_url',info['url'])
142return info
Note: See TracBrowser for help on using the repository browser.