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

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

disable time logging (in custom)

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