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

Last change on this file since 2761 was 2745, checked in by joachim, 17 years ago

add timing info,

  • Property svn:keywords set to Id
File size: 3.9 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 2745 2007-11-23 13:32:27Z joachim $
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')
25
26
27info = {}
28member_id = str(member)
29#from Products.zdb import set_trace;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_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
48student_path = "%s/campus/students/%s" % (context.portal_url(),student_id)
49res = context.students_catalog(id = student_id)
50if not res:
51    return None
52st_brain = res[0]
53#from Products.zdb import set_trace;set_trace()
54for field in context.students_catalog.schema():
55    info[field] = getattr(st_brain,field)
56
57#res = context.portal_catalog(portal_type='Student',id = student_id)
58#if res:
59#    info['review_state'] = res[0].review_state
60
61info['review_state'] = context.getStudentReviewState()
62
63info['session'] = False
64if st_brain.matric_no:
65    res = context.results_import(matric_no = st_brain.matric_no)
66    if res:
67       info['session'] = True
68
69info['base_info'] = context.getFormattedStudentEntry(st_brain)
70
71info['id'] = student_id
72items = []
73s_edit_links = {'StudentApplication': 'application_edit_form',
74              'StudentAccommodation': 'reserve_accommodation',
75              'StudentClearance': 'clearance_edit_form',
76              'StudentPersonal': 'personal_edit_form',
77              }
78s_view_links = {'StudentApplication': 'application_view',
79              'StudentAccommodation': 'accommodation_view',
80              'StudentClearance': 'clearance_view',
81              'StudentPersonal': 'personal_view',
82              'StudentStudyCourse': 'study_course_view',
83              'PaymentsFolder': 'payments_view',
84              }
85#logger.info("before search")
86starttime = DateTime.DateTime().timeTime()
87sos = context.portal_catalog(container_path=student_path_root)
88logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime))
89starttime = DateTime.DateTime().timeTime()
90for so in sos:
91    row = {}
92    row['id'] = so.getId
93    row['title'] = so.Title
94    url = row['url'] = "%s/%s" % (student_path,so.getId)
95    row['type'] = so.portal_type
96    review_state = row['review_state'] = so.review_state
97    row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer
98    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
99    row['s_view_link'] = "%s/%s" % (url,sv_link)
100    se_link = s_edit_links.get(so.portal_type,None)
101    row['s_edit_link'] = None
102    if se_link:
103        row['s_edit_link'] = "%s/%s" % (url,se_link)
104    row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\
105                    and so.portal_type not in  ('StudentPume','StudentAccommodation','PaymentsFolder',) or\
106                    so.portal_type == 'StudentStudyCourse'
107    items.append(row)
108logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime))
109items.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
110info['items'] = items
111info['member'] = member
112return info
113
Note: See TracBrowser for help on using the repository browser.