## Script (Python) "getStudentInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getStudentInfo.py 913 2006-11-21 10:49:45Z henrik $ """ return Info about the current Student """ request = context.REQUEST form = request.form fget = form.get wf = context.portal_workflow mtool = context.portal_membership member = mtool.getAuthenticatedMember() path_info = request.get('PATH_INFO').split('/') info = {} member_id = str(member) if student is None: if mtool.isAnonymousUser(): return None elif not context.isStudent() and 'students' in path_info: student_id = path_info[path_info.index('students')+1] else: student_id = member_id else: student_id = student.getId() roles = member.getRoles() student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) student = context.restrictedTraverse(student_path,default=None) if student is None or student.portal_type != 'Student': return None ##res = context.portal_catalog(id = student_id,portal_type='Student') ##if not res:# or len(res) > 1: ## return None ##brain = res[-1] ##student = brain.getObject() info['review_state'] = wf.getInfoFor(student,'review_state',None) info['student'] = student info['id'] = student.getId() info['url'] = student.absolute_url() info['student_doc'] = student.getContent() info['app'] = student.application info['app_doc'] = student.application.getContent() info['per'] = student.personal info['per_doc'] = student.personal.getContent() course = getattr(student,'study_course',None) # info['course'] = course if course: info['course_doc'] = student.study_course.getContent() info['sex'] = 'male' if info['per_doc'].sex: info['sex'] = 'female' # acco = getattr(student,'accommodation_2006',None) info['acco'] = acco if acco is not None: info['acco_doc'] = acco.getContent() info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) # clear = getattr(student,'clearance',None) info['clear'] = clear if clear is not None: info['clear_doc'] = clear.getContent() info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) # pume = getattr(student,'pume',None) info['pume'] = pume if pume is not None: info['pume_doc'] = pume.getContent() info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) else: info['pume'] = None items = [] s_edit_links = {'StudentApplication': 'application_edit_form', 'StudentAccommodation': 'reserve_accommodation', 'StudentClearance': 'clearance_edit_form', 'StudentPersonal': '', } s_view_links = {'StudentApplication': 'application_view', 'StudentAccommodation': 'accommodation_view', 'StudentClearance': 'clearance_view', 'StudentPersonal': None, 'StudentStudyCourse': 'study_course_view', 'StudentPume': 'pume_view', } sos = context.portal_catalog(container_path=student_path) for so in sos: row = {} soo = so.getObject() sod = soo.getContent() row['id'] = soo.getId() row['title'] = sod.Title() row['url'] = soo.absolute_url() row['type'] = so.portal_type row['is_editable'] = mtool.checkPermission('Modify portal content', soo) sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) se_link = s_edit_links.get(so.portal_type,None) row['s_edit_link'] = None if se_link: row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) row['review_state'] = so.review_state row['display'] = so.review_state in ('opened','closed',) items.append(row) info['items'] = items request.set('student_id',student_id) request.set('student_url',info['url']) return info