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
RevLine 
[845]1## Script (Python) "getStudentInfo"
[535]2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[1048]7##parameters=student=None, with_items=None
[535]8##title=
9##
[805]10# $Id: getStudentInfo.py 1145 2006-12-28 21:35:07Z henrik $
[535]11"""
12return Info about the current Student
13"""
14request = context.REQUEST
[563]15form = request.form
16fget = form.get
[535]17wf = context.portal_workflow
18mtool = context.portal_membership
19member = mtool.getAuthenticatedMember()
20path_info = request.get('PATH_INFO').split('/')
[741]21
[1006]22import logging
[1082]23logger = logging.getLogger('Student.Info')
[1006]24
[1144]25from DateTime import DateTime
26
[535]27info = {}
28member_id = str(member)
[1006]29#from Products.zdb import set_trace
30#set_trace()
31student_id = None
[645]32if student is None:
[1006]33    while True:
34        if mtool.isAnonymousUser():
35            return None
36        try:
37            requested_id = path_info[path_info.index('students')+1]
[1016]38        except (ValueError,IndexError):
[1006]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:
[1048]45            logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id))
[1006]46            student_id = member_id
[1025]47            mtool.assertViewable(context)
[1006]48            break
[748]49        student_id = member_id
[1006]50        break
[645]51else:
52    student_id = student.getId()
[1006]53
[1048]54#roles = member.getRoles()
[787]55student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
[785]56student = context.restrictedTraverse(student_path,default=None)
[971]57
[1006]58if student is None or student.portal_type != "Student":
[639]59    return None
[785]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()
[1144]65
66creation_date = DateTime(student.creation_date)
67info['penalty'] = creation_date.lessThan(DateTime('2006/12/5'))\
[1145]68                  and DateTime().greaterThan(DateTime('2006/12/30'))
[1144]69
[742]70info['review_state'] = wf.getInfoFor(student,'review_state',None)
[535]71info['student'] = student
[584]72info['id'] = student.getId()
[662]73info['url'] = student.absolute_url()
[538]74info['student_doc'] = student.getContent()
[535]75info['app'] = student.application
76info['app_doc'] = student.application.getContent()
[966]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'
[785]86course = getattr(student,'study_course',None)
87if course:
[1025]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
[867]102#
[812]103acco = getattr(student,'accommodation_2006',None)
[785]104info['acco'] = acco
105if acco is not None:
[639]106    info['acco_doc'] = acco.getContent()
[748]107    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
[867]108#
[785]109clear = getattr(student,'clearance',None)
110info['clear'] = clear
111if clear is not None:
[766]112    info['clear_doc'] = clear.getContent()
113    info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None)
[867]114#
[785]115pume = getattr(student,'pume',None)
116info['pume'] = pume
117if pume is not None:
[768]118    info['pume_doc'] = pume.getContent()
119    info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None)
120else:
[770]121    info['pume'] = None
[659]122
[1067]123if not with_items:
124    return info
125
[659]126items = []
[803]127s_edit_links = {'StudentApplication': 'application_edit_form',
[814]128              'StudentAccommodation': 'reserve_accommodation',
[803]129              'StudentClearance': 'clearance_edit_form',
[672]130              'StudentPersonal': '',
131              }
[770]132s_view_links = {'StudentApplication': 'application_view',
[748]133              'StudentAccommodation': 'accommodation_view',
[768]134              'StudentClearance': 'clearance_view',
[723]135              'StudentPersonal': None,
136              'StudentStudyCourse': 'study_course_view',
[768]137              'StudentPume': 'pume_view',
[674]138              }
[659]139sos = context.portal_catalog(container_path=student_path)
[656]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()
[659]147    row['type'] = so.portal_type
[656]148    row['is_editable'] = mtool.checkPermission('Modify portal content', soo)
[739]149    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
[723]150    row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link)
[674]151    se_link = s_edit_links.get(so.portal_type,None)
152    row['s_edit_link'] = None
153    if se_link:
[767]154        row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link)
[659]155    row['review_state'] = so.review_state
[1132]156    row['display'] = so.review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',) and so.portal_type != 'StudentPume' or so.portal_type == 'StudentStudyCourse'
[656]157    items.append(row)
158info['items'] = items
[1144]159
[742]160request.set('student_id',student_id)
161request.set('student_url',info['url'])
[535]162return info
Note: See TracBrowser for help on using the repository browser.