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

Last change on this file since 2831 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
RevLine 
[1571]1## Script (Python) "getStudentFolderInfo"
[1185]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"""
[2745]14import DateTime
[1185]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
[1571]24logger = logging.getLogger('Skins.getStudentFolderInfo')
[2806]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
[1185]30
31
32info = {}
33member_id = str(member)
[1243]34#from Products.zdb import set_trace;set_trace()
[1185]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:
[1571]46        logger.info('%s tried to access %s' % (member_id,requested_id))
[1185]47        student_id = member_id
48        mtool.assertViewable(context)
49        break
50    student_id = member_id
51    break
[1431]52student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
53student_path = "%s/campus/students/%s" % (context.portal_url(),student_id)
[2806]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:
[1185]61    return None
[2831]62
[1185]63#from Products.zdb import set_trace;set_trace()
64for field in context.students_catalog.schema():
[2806]65    info[field] = getattr(student_record,field)
[1359]66
[1871]67#res = context.portal_catalog(portal_type='Student',id = student_id)
68#if res:
69#    info['review_state'] = res[0].review_state
70
[2806]71#info['review_state'] = context.getStudentReviewState()
[1871]72
[1422]73info['session'] = False
[2806]74if student_record.matric_no:
75    res = context.results_import(matric_no = student_record.matric_no)
[1422]76    if res:
77       info['session'] = True
78
[2831]79info['base_info'] = context.getFormattedStudentEntry(student_record)
[1472]80
[1185]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',
[1243]93              'PaymentsFolder': 'payments_view',
[1185]94              }
[2745]95#logger.info("before search")
[2831]96#starttime = DateTime.DateTime().timeTime()
[2806]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()
[2831]123#logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime))
124#starttime = DateTime.DateTime().timeTime()
[2806]125for subobject in subobjects:
[1185]126    row = {}
[2806]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)
[1472]132    row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer
[2806]133    sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view"
[1185]134    row['s_view_link'] = "%s/%s" % (url,sv_link)
[2806]135    se_link = s_edit_links.get(subobject.portal_type,None)
[1185]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',)\
[2806]140                    and subobject.portal_type not in  ('StudentPume','StudentAccommodation','PaymentsFolder',) or\
141                    subobject.portal_type == 'StudentStudyCourse'
[1185]142    items.append(row)
[2831]143#logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime))
[2477]144items.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
[1185]145info['items'] = items
[1214]146info['member'] = member
[1185]147return info
[1258]148
Note: See TracBrowser for help on using the repository browser.