source: WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py @ 837

Last change on this file since 837 was 814, checked in by Henrik Bettermann, 18 years ago

bug fixed

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1## Script (Python) "cpsdocument_edit"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=student=None
8##title=
9##
10# $Id: getStudentInfo.py 814 2006-11-09 16:54:54Z henrik $
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('/')
21roles = member.getRoles()
22
23info = {}
24info['is_manager'] = context.isManager()
25info['is_student'] = context.isStudent()
26member_id = str(member)
27if student is None:
28    if mtool.isAnonymousUser():
29        return None
30    elif context.isManager() and 'students' in path_info:
31        student_id = path_info[path_info.index('students')+1]
32    else:
33        student_id = member_id
34else:
35    student_id = student.getId()
36student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
37student = context.restrictedTraverse(student_path,default=None)
38if student is None or student.portal_type != 'Student':
39    return None
40##res = context.portal_catalog(id = student_id,portal_type='Student')
41##if not res:# or len(res) > 1:
42##    return None
43##brain = res[-1]
44##student = brain.getObject()
45info['review_state'] = wf.getInfoFor(student,'review_state',None)
46info['student'] = student
47info['id'] = student.getId()
48info['url'] = student.absolute_url()
49info['student_doc'] = student.getContent()
50info['app'] = student.application
51info['app_doc'] = student.application.getContent()
52info['per'] = student.personal
53info['per_doc'] = student.personal.getContent()
54course = getattr(student,'study_course',None)
55info['course'] = course
56if course:
57    info['course_doc'] = student.study_course.getContent()
58info['sex'] = 'male'
59if info['per_doc'].sex:
60    info['sex'] = 'female'
61##res = context.portal_catalog(container_path=student_path,
62##                             portal_type='StudentAccommodation')
63##if res:
64##    acco = res[0].getObject()
65acco = getattr(student,'accommodation_2006',None)
66#if acco.portal_type != "StudentAccommodation":
67#    acco = None
68info['acco'] = acco
69if acco is not None:
70    info['acco_doc'] = acco.getContent()
71    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
72##res = context.portal_catalog(container_path=student_path,
73##                             portal_type='StudentClearance')
74##if res:
75##    clear = res[0].getObject()
76##    info['clear'] = clear
77clear = getattr(student,'clearance',None)
78info['clear'] = clear
79if clear is not None:
80    info['clear_doc'] = clear.getContent()
81    info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None)
82
83##res = context.portal_catalog(container_path=student_path,
84##                             portal_type='StudentPume')
85##if res:
86##    pume = res[0].getObject()
87##    info['pume'] = clear
88pume = getattr(student,'pume',None)
89info['pume'] = pume
90if pume is not None:
91    info['pume_doc'] = pume.getContent()
92    info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None)
93else:
94    info['pume'] = None
95
96items = []
97s_edit_links = {'StudentApplication': 'application_edit_form',
98              'StudentAccommodation': 'reserve_accommodation',
99              'StudentClearance': 'clearance_edit_form',
100              'StudentPersonal': '',
101              }
102s_view_links = {'StudentApplication': 'application_view',
103              'StudentAccommodation': 'accommodation_view',
104              'StudentClearance': 'clearance_view',
105              'StudentPersonal': None,
106              'StudentStudyCourse': 'study_course_view',
107              'StudentPume': 'pume_view',
108              }
109sos = context.portal_catalog(container_path=student_path)
110for so in sos:
111    row = {}
112    soo = so.getObject()
113    sod = soo.getContent()
114    row['id'] = soo.getId()
115    row['title'] = sod.Title()
116    row['url'] = soo.absolute_url()
117    row['type'] = so.portal_type
118    row['is_editable'] = mtool.checkPermission('Modify portal content', soo)
119    sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view"
120    row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link)
121    se_link = s_edit_links.get(so.portal_type,None)
122    row['s_edit_link'] = None
123    if se_link:
124        row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link)
125    row['review_state'] = so.review_state
126    row['display'] = so.review_state in ('opened','closed','public','bed_reserved',) #or\
127                     #so.portal_type in ("StudentAccommodation","StudentStudyCourse")
128    items.append(row)
129info['items'] = items
130request.set('student_id',student_id)
131request.set('student_url',info['url'])
132return info
Note: See TracBrowser for help on using the repository browser.