## Script (Python) "cpsdocument_edit" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getStudentInfo.py 486 2006-09-06 10:09:39Z joachim $ """ 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('/') roles = member.getRoles() info = {} info['is_manager'] = context.isManager() info['is_student'] = context.isStudent() member_id = str(member) if student is None: if mtool.isAnonymousUser(): return None elif context.isManager() and 'students' in path_info: student_id = path_info[path_info.index('students')+1] else: student_id = member_id else: student_id = student.getId() 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' ##res = context.portal_catalog(container_path=student_path, ## portal_type='StudentAccommodation') ##if res: ## acco = res[0].getObject() acco = getattr(student,'accommodation',None) if acco.portal_type != "StudentAccomodation": acco = None info['acco'] = acco if acco is not None: info['acco_doc'] = acco.getContent() info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) ##res = context.portal_catalog(container_path=student_path, ## portal_type='StudentClearance') ##if res: ## clear = res[0].getObject() ## info['clear'] = clear 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) ##res = context.portal_catalog(container_path=student_path, ## portal_type='StudentPume') ##if res: ## pume = res[0].getObject() ## info['pume'] = clear 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', 'StudentAccommodation': '', 'StudentClearance': 'clearance_edit', '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','public',) #or\ #so.portal_type in ("StudentAccommodation","StudentStudyCourse") items.append(row) info['items'] = items request.set('student_id',student_id) request.set('student_url',info['url']) return info