source: WAeUP_SRP/trunk/skins/waeup_student/getStudentFolderInfo.py @ 1225

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

member record link beautified

  • Property svn:keywords set to Id
File size: 3.1 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=with_items=None
8##title=
9##
10# $Id: getStudentFolderInfo.py 1214 2007-01-06 15:42: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
25
26info = {}
27member_id = str(member)
28#from Products.zdb import set_trace
29#set_trace()
30is_student = info['is_student'] = context.isStudent()
31is_staff = info['is_staff'] = context.isStaff()
32is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer()
33while True:
34    if mtool.isAnonymousUser():
35        return None
36    requested_id = context.getStudentId()
37    if not is_student and requested_id:
38        student_id = requested_id
39        break
40    if member_id != requested_id:
41        logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id))
42        student_id = member_id
43        mtool.assertViewable(context)
44        break
45    student_id = member_id
46    break
47student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
48res = context.students_catalog(id = student_id)
49if not res:
50    return None
51st_brain = res[0]
52#from Products.zdb import set_trace;set_trace()
53for field in context.students_catalog.schema():
54    info[field] = getattr(st_brain,field)
55res = context.portal_catalog(portal_type='Student',id = student_id)
56if res:
57    info['review_state'] = res[0].review_state
58info['id'] = student_id
59items = []
60s_edit_links = {'StudentApplication': 'application_edit_form',
61              'StudentAccommodation': 'reserve_accommodation',
62              'StudentClearance': 'clearance_edit_form',
63              'StudentPersonal': 'personal_edit_form',
64              }
65s_view_links = {'StudentApplication': 'application_view',
66              'StudentAccommodation': 'accommodation_view',
67              'StudentClearance': 'clearance_view',
68              'StudentPersonal': 'personal_view',
69              'StudentStudyCourse': 'study_course_view',
70              'StudentPume': 'pume_view',
71              }
72sos = context.portal_catalog(container_path=student_path)
73for so in sos:
74    row = {}
75    row['id'] = so.getId
76    row['title'] = so.Title
77    url = row['url'] = "%s/%s" % (student_path,so.getId)
78    row['type'] = so.portal_type
79    review_state = row['review_state'] = so.review_state
80    row['is_editable'] = (is_student and review_state == "opened") or not is_student
81    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
82    row['s_view_link'] = "%s/%s" % (url,sv_link)
83    se_link = s_edit_links.get(so.portal_type,None)
84    row['s_edit_link'] = None
85    if se_link:
86        row['s_edit_link'] = "%s/%s" % (url,se_link)
87    row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\
88                    and so.portal_type != 'StudentPume' or\
89                    so.portal_type == 'StudentStudyCourse'
90    items.append(row)
91info['items'] = items
92info['member'] = member
93return info
Note: See TracBrowser for help on using the repository browser.