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

Last change on this file since 2686 was 2477, checked in by joachim, 17 years ago

show student objects sorted by title

  • Property svn:keywords set to Id
File size: 3.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 2477 2007-10-30 08:59:54Z joachim $
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('Skins.getStudentFolderInfo')
24
25
26info = {}
27member_id = str(member)
28#from Products.zdb import set_trace;set_trace()
29is_student = info['is_student'] = context.isStudent()
30is_staff = info['is_staff'] = context.isStaff()
31is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer()
32while True:
33    if mtool.isAnonymousUser():
34        return None
35    requested_id = context.getStudentId()
36    if not is_student and requested_id:
37        student_id = requested_id
38        break
39    if member_id != requested_id:
40        logger.info('%s tried to access %s' % (member_id,requested_id))
41        student_id = member_id
42        mtool.assertViewable(context)
43        break
44    student_id = member_id
45    break
46student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
47student_path = "%s/campus/students/%s" % (context.portal_url(),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)
55
56#res = context.portal_catalog(portal_type='Student',id = student_id)
57#if res:
58#    info['review_state'] = res[0].review_state
59
60info['review_state'] = context.getStudentReviewState()
61
62info['session'] = False
63if st_brain.matric_no:
64    res = context.results_import(matric_no = st_brain.matric_no)
65    if res:
66       info['session'] = True
67
68
69info['id'] = student_id
70items = []
71s_edit_links = {'StudentApplication': 'application_edit_form',
72              'StudentAccommodation': 'reserve_accommodation',
73              'StudentClearance': 'clearance_edit_form',
74              'StudentPersonal': 'personal_edit_form',
75              }
76s_view_links = {'StudentApplication': 'application_view',
77              'StudentAccommodation': 'accommodation_view',
78              'StudentClearance': 'clearance_view',
79              'StudentPersonal': 'personal_view',
80              'StudentStudyCourse': 'study_course_view',
81              'PaymentsFolder': 'payments_view',
82              }
83sos = context.portal_catalog(container_path=student_path_root)
84for so in sos:
85    row = {}
86    row['id'] = so.getId
87    row['title'] = so.Title
88    url = row['url'] = "%s/%s" % (student_path,so.getId)
89    row['type'] = so.portal_type
90    review_state = row['review_state'] = so.review_state
91    row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer
92    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
93    row['s_view_link'] = "%s/%s" % (url,sv_link)
94    se_link = s_edit_links.get(so.portal_type,None)
95    row['s_edit_link'] = None
96    if se_link:
97        row['s_edit_link'] = "%s/%s" % (url,se_link)
98    row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\
99                    and so.portal_type not in  ('StudentPume','StudentAccommodation','PaymentsFolder',) or\
100                    so.portal_type == 'StudentStudyCourse'
101    items.append(row)
102items.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
103info['items'] = items
104info['member'] = member
105return info
106
Note: See TracBrowser for help on using the repository browser.