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

Last change on this file since 1112 was 1103, checked in by Henrik Bettermann, 18 years ago

also display accommodation object

  • Property svn:keywords set to Id
File size: 4.9 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, with_items=None
8##title=
9##
10# $Id: getStudentInfo.py 1103 2006-12-20 10:54:40Z henrik $
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('Student.Info')
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,IndexError):
37            student_id = member_id
38            break
39        if not context.isStudent() and 'students' in path_info:
40            student_id = requested_id
41            break
42        if member_id != requested_id:
43            logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id))
44            student_id = member_id
45            mtool.assertViewable(context)
46            break
47        student_id = member_id
48        break
49else:
50    student_id = student.getId()
51
52#roles = member.getRoles()
53student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
54student = context.restrictedTraverse(student_path,default=None)
55
56if student is None or student.portal_type != "Student":
57    return None
58##res = context.portal_catalog(id = student_id,portal_type='Student')
59##if not res:# or len(res) > 1:
60##    return None
61##brain = res[-1]
62##student = brain.getObject()
63info['review_state'] = wf.getInfoFor(student,'review_state',None)
64info['student'] = student
65info['id'] = student.getId()
66info['url'] = student.absolute_url()
67info['student_doc'] = student.getContent()
68info['app'] = student.application
69info['app_doc'] = student.application.getContent()
70info['per'] = getattr(student,'personal',None)
71info['sex'] = 'male'
72if info['per'] is not None:
73    info['per_doc'] = student.personal.getContent()
74    if info['per_doc'].sex:
75        info['sex'] = 'female'
76else:
77    if info['app_doc'].jamb_sex == "F":
78        info['sex'] = 'female'
79course = getattr(student,'study_course',None)
80if course:
81    cert_id = course.getContent().study_course
82    res = context.portal_catalog(portal_type = "Certificate", id = cert_id)
83    ci = {}
84    if len(res) > 0:
85        info['course'] = course
86        brain = res[0]
87        ci['study_course'] = brain.getId
88        ci['title'] = brain.Title
89        pl = brain.getPath().split('/')
90        ci['faculty'] = pl[-4]
91        ci['department'] = pl[-3]
92        info['course_doc'] = ci
93    else:
94        info['course'] = None
95#
96acco = getattr(student,'accommodation_2006',None)
97info['acco'] = acco
98if acco is not None:
99    info['acco_doc'] = acco.getContent()
100    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
101#
102clear = getattr(student,'clearance',None)
103info['clear'] = clear
104if clear is not None:
105    info['clear_doc'] = clear.getContent()
106    info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None)
107#
108pume = getattr(student,'pume',None)
109info['pume'] = pume
110if pume is not None:
111    info['pume_doc'] = pume.getContent()
112    info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None)
113else:
114    info['pume'] = None
115
116if not with_items:
117    return info
118
119items = []
120s_edit_links = {'StudentApplication': 'application_edit_form',
121              'StudentAccommodation': 'reserve_accommodation',
122              'StudentClearance': 'clearance_edit_form',
123              'StudentPersonal': '',
124              }
125s_view_links = {'StudentApplication': 'application_view',
126              'StudentAccommodation': 'accommodation_view',
127              'StudentClearance': 'clearance_view',
128              'StudentPersonal': None,
129              'StudentStudyCourse': 'study_course_view',
130              'StudentPume': 'pume_view',
131              }
132sos = context.portal_catalog(container_path=student_path)
133for so in sos:
134    row = {}
135    soo = so.getObject()
136    sod = soo.getContent()
137    row['id'] = soo.getId()
138    row['title'] = sod.Title()
139    row['url'] = soo.absolute_url()
140    row['type'] = so.portal_type
141    row['is_editable'] = mtool.checkPermission('Modify portal content', soo)
142    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
143    row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link)
144    se_link = s_edit_links.get(so.portal_type,None)
145    row['s_edit_link'] = None
146    if se_link:
147        row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link)
148    row['review_state'] = so.review_state
149    row['display'] = so.review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',) or so.portal_type == 'StudentStudyCourse'
150    items.append(row)
151info['items'] = items
152request.set('student_id',student_id)
153request.set('student_url',info['url'])
154return info
Note: See TracBrowser for help on using the repository browser.