## Script (Python) "getStudentInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None, with_items=None ##title= ## # $Id: getStudentInfo.py 1179 2007-01-02 21:29:17Z 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('/') import logging logger = logging.getLogger('Student.Info') info = {} member_id = str(member) #from Products.zdb import set_trace #set_trace() student_id = None if student is None: while True: if mtool.isAnonymousUser(): return None try: requested_id = path_info[path_info.index('students')+1] except (ValueError,IndexError): student_id = member_id break if not context.isStudent() and 'students' in path_info: student_id = requested_id break if member_id != requested_id: logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id)) student_id = member_id mtool.assertViewable(context) break student_id = member_id break 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'] = getattr(student,'personal',None) #info['sex'] = 'male' #if info['per'] is not None: # info['per_doc'] = student.personal.getContent() # if info['per_doc'].sex: # info['sex'] = 'female' #else: # if info['app_doc'].jamb_sex == "F": # info['sex'] = 'female' course = getattr(student,'study_course',None) if course: cert_id = course.getContent().study_course res = context.portal_catalog(portal_type = "Certificate", id = cert_id) ci = {} if len(res) > 0: info['course'] = course brain = res[0] ci['study_course'] = brain.getId ci['title'] = brain.Title pl = brain.getPath().split('/') ci['faculty'] = pl[-4] ci['department'] = pl[-3] info['course_doc'] = ci else: info['course'] = None # 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 if not with_items: return info items = [] s_edit_links = {'StudentApplication': 'application_edit_form', 'StudentAccommodation': 'reserve_accommodation', 'StudentClearance': 'clearance_edit_form', 'StudentPersonal': 'personal_edit_form', } s_view_links = {'StudentApplication': 'application_view', 'StudentAccommodation': 'accommodation_view', 'StudentClearance': 'clearance_view', 'StudentPersonal': 'personal_view', '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 if info['review_state'] in ('returning', 'school_fee_pin_entered', 'courses_registered', 'courses_validated',): row['display'] = so.review_state in ('opened', 'bed_reserved', 'maintenance_fee_paid',) or so.portal_type == 'StudentStudyCourse' else: row['display'] = so.review_state in ('opened', 'closed', 'bed_reserved', 'maintenance_fee_paid',) and\ so.portal_type not in ('StudentPume',) or\ so.portal_type == 'StudentStudyCourse' items.append(row) info['items'] = items request.set('student_id',student_id) request.set('student_url',info['url']) return info