source: WAeUP_SRP/base/skins/waeup_student/getStudentFolderInfo.py @ 3106

Last change on this file since 3106 was 2983, checked in by Henrik Bettermann, 17 years ago

fix

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1## Script (Python) "getStudentFolderInfo"
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 2983 2008-01-06 22:50:32Z henrik $
11"""
12return Info about the current Student
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18"""
19import DateTime
20request = context.REQUEST
21form = request.form
22fget = form.get
23wf = context.portal_workflow
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26path_info = request.get('PATH_INFO').split('/')
27
28import logging
29logger = logging.getLogger('Skins.getStudentFolderInfo')
30from Products.AdvancedQuery import Eq, Between, Le,In
31try:
32    aq_portal = context.portal_catalog.evalAdvancedQuery
33except:
34    aq_portal = context.portal_catalog_real.evalAdvancedQuery
35
36
37member_id = str(member)
38#from Products.zdb import set_trace;set_trace()
39# info = {}
40# is_student = info['is_student'] = context.isStudent()
41# is_staff = info['is_staff'] = context.isStaff()
42# is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer()
43# while True:
44#     if mtool.isAnonymousUser():
45#         return None
46#     requested_id = context.getStudentId()
47#     if not is_student and requested_id:
48#         student_id = requested_id
49#         break
50#     if member_id != requested_id:
51#         logger.info('%s tried to access %s' % (member_id,requested_id))
52#         student_id = member_id
53#         mtool.assertViewable(context)
54#         break
55#     student_id = member_id
56#     break
57info = context.waeup_tool.getAccessInfo(context)
58student_id = info['student_id']
59if student_id is None:
60    return None
61
62student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
63student_path = "%s/campus/students/%s" % (context.portal_url(),student_id)
64students_folder = context.portal_url.getPortalObject().campus.students
65
66student_record = context.students_catalog.getRecordByKey(student_id)
67if student_record is None:
68    return None
69
70#from Products.zdb import set_trace;set_trace()
71for field in context.students_catalog.schema():
72    info[field] = getattr(student_record,field)
73
74#info['review_state'] = context.getStudentReviewState()
75
76info['session'] = False
77if student_record.matric_no:
78    res = context.results_import(matric_no = student_record.matric_no)
79    if res:
80       info['session'] = True
81
82info['base_info'] = context.getFormattedStudentEntry(student_record)
83
84info['id'] = student_id
85items = []
86s_edit_links = {'StudentApplication': 'application_edit_form',
87              'StudentAccommodation': 'reserve_accommodation',
88              'StudentClearance': 'clearance_edit_form',
89              'StudentPersonal': 'personal_edit_form',
90              }
91s_view_links = {'StudentApplication': 'application_view',
92              'StudentAccommodation': 'accommodation_view',
93              'StudentClearance': 'clearance_view',
94              'StudentPersonal': 'personal_view',
95              'StudentStudyCourse': 'study_course_view',
96              'PaymentsFolder': 'payments_view',
97              }
98
99student_obj = getattr(students_folder,student_id)
100subobjects = student_obj.objectValues()
101
102for subobject in subobjects:
103    row = {}
104    row['id'] = subobject.getId()
105    row['title'] = subobject.Title()
106    url = row['url'] = subobject.absolute_url()
107    row['type'] = subobject.portal_type
108    review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None)
109    row['is_editable'] = (info['is_student'] and review_state == "opened") or info['is_sectionofficer']
110    sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view"
111    row['s_view_link'] = "%s/%s" % (url,sv_link)
112    se_link = s_edit_links.get(subobject.portal_type,None)
113    row['s_edit_link'] = None
114    if se_link:
115        row['s_edit_link'] = "%s/%s" % (url,se_link)
116    row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\
117                    and subobject.portal_type not in  ('StudentPume','StudentAccommodation','PaymentsFolder',) or\
118                    subobject.portal_type == 'StudentStudyCourse'
119    items.append(row)
120
121items.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
122info['items'] = items
123info['member'] = member
124
125try:
126    current_level = int(info['level'])
127except:
128    current_level = 0
129info['transition_return_allowed'] = info['review_state'] == 'school_fee_paid' and current_level > 100 and info['is_sectionofficer']
130info['transition_pay_school_fee_allowed'] = info['review_state'] == 'returning' and info['is_sectionofficer']
131
132return info
133
Note: See TracBrowser for help on using the repository browser.