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

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

wrong date corrected

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