[845] | 1 | ## Script (Python) "getStudentInfo" |
---|
[535] | 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 | ## |
---|
[805] | 10 | # $Id: getStudentInfo.py 971 2006-11-30 19:31:01Z joachim $ |
---|
[535] | 11 | """ |
---|
| 12 | return Info about the current Student |
---|
| 13 | """ |
---|
| 14 | request = context.REQUEST |
---|
[563] | 15 | form = request.form |
---|
| 16 | fget = form.get |
---|
[535] | 17 | wf = context.portal_workflow |
---|
| 18 | mtool = context.portal_membership |
---|
| 19 | member = mtool.getAuthenticatedMember() |
---|
| 20 | path_info = request.get('PATH_INFO').split('/') |
---|
[741] | 21 | |
---|
[535] | 22 | info = {} |
---|
| 23 | member_id = str(member) |
---|
[645] | 24 | if student is None: |
---|
[787] | 25 | if mtool.isAnonymousUser(): |
---|
| 26 | return None |
---|
[885] | 27 | elif not context.isStudent() and 'students' in path_info: |
---|
[741] | 28 | student_id = path_info[path_info.index('students')+1] |
---|
[646] | 29 | else: |
---|
[748] | 30 | student_id = member_id |
---|
[645] | 31 | else: |
---|
| 32 | student_id = student.getId() |
---|
[883] | 33 | roles = member.getRoles() |
---|
[787] | 34 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
[785] | 35 | student = context.restrictedTraverse(student_path,default=None) |
---|
[971] | 36 | #from Products.zdb import set_trace |
---|
| 37 | #set_trace() |
---|
| 38 | |
---|
[785] | 39 | if student is None or student.portal_type != 'Student': |
---|
[639] | 40 | return None |
---|
[785] | 41 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
| 42 | ##if not res:# or len(res) > 1: |
---|
| 43 | ## return None |
---|
| 44 | ##brain = res[-1] |
---|
| 45 | ##student = brain.getObject() |
---|
[742] | 46 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
[535] | 47 | info['student'] = student |
---|
[584] | 48 | info['id'] = student.getId() |
---|
[662] | 49 | info['url'] = student.absolute_url() |
---|
[538] | 50 | info['student_doc'] = student.getContent() |
---|
[535] | 51 | info['app'] = student.application |
---|
| 52 | info['app_doc'] = student.application.getContent() |
---|
[966] | 53 | info['per'] = getattr(student,'personal',None) |
---|
| 54 | info['sex'] = 'male' |
---|
| 55 | if info['per'] is not None: |
---|
| 56 | info['per_doc'] = student.personal.getContent() |
---|
| 57 | if info['per_doc'].sex: |
---|
| 58 | info['sex'] = 'female' |
---|
| 59 | else: |
---|
| 60 | if info['app_doc'].jamb_sex == "F": |
---|
| 61 | info['sex'] = 'female' |
---|
[785] | 62 | course = getattr(student,'study_course',None) |
---|
| 63 | info['course'] = course |
---|
| 64 | if course: |
---|
| 65 | info['course_doc'] = student.study_course.getContent() |
---|
[867] | 66 | # |
---|
[812] | 67 | acco = getattr(student,'accommodation_2006',None) |
---|
[785] | 68 | info['acco'] = acco |
---|
| 69 | if acco is not None: |
---|
[639] | 70 | info['acco_doc'] = acco.getContent() |
---|
[748] | 71 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
[867] | 72 | # |
---|
[785] | 73 | clear = getattr(student,'clearance',None) |
---|
| 74 | info['clear'] = clear |
---|
| 75 | if clear is not None: |
---|
[766] | 76 | info['clear_doc'] = clear.getContent() |
---|
| 77 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
[867] | 78 | # |
---|
[785] | 79 | pume = getattr(student,'pume',None) |
---|
| 80 | info['pume'] = pume |
---|
| 81 | if pume is not None: |
---|
[768] | 82 | info['pume_doc'] = pume.getContent() |
---|
| 83 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
| 84 | else: |
---|
[770] | 85 | info['pume'] = None |
---|
[659] | 86 | |
---|
| 87 | items = [] |
---|
[803] | 88 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
[814] | 89 | 'StudentAccommodation': 'reserve_accommodation', |
---|
[803] | 90 | 'StudentClearance': 'clearance_edit_form', |
---|
[672] | 91 | 'StudentPersonal': '', |
---|
| 92 | } |
---|
[770] | 93 | s_view_links = {'StudentApplication': 'application_view', |
---|
[748] | 94 | 'StudentAccommodation': 'accommodation_view', |
---|
[768] | 95 | 'StudentClearance': 'clearance_view', |
---|
[723] | 96 | 'StudentPersonal': None, |
---|
| 97 | 'StudentStudyCourse': 'study_course_view', |
---|
[768] | 98 | 'StudentPume': 'pume_view', |
---|
[674] | 99 | } |
---|
[659] | 100 | sos = context.portal_catalog(container_path=student_path) |
---|
[656] | 101 | for so in sos: |
---|
| 102 | row = {} |
---|
| 103 | soo = so.getObject() |
---|
| 104 | sod = soo.getContent() |
---|
| 105 | row['id'] = soo.getId() |
---|
| 106 | row['title'] = sod.Title() |
---|
| 107 | row['url'] = soo.absolute_url() |
---|
[659] | 108 | row['type'] = so.portal_type |
---|
[656] | 109 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
[739] | 110 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
[723] | 111 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
[674] | 112 | se_link = s_edit_links.get(so.portal_type,None) |
---|
| 113 | row['s_edit_link'] = None |
---|
| 114 | if se_link: |
---|
[767] | 115 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
[659] | 116 | row['review_state'] = so.review_state |
---|
[849] | 117 | row['display'] = so.review_state in ('opened','closed',) |
---|
[656] | 118 | items.append(row) |
---|
| 119 | info['items'] = items |
---|
[742] | 120 | request.set('student_id',student_id) |
---|
| 121 | request.set('student_url',info['url']) |
---|
[535] | 122 | return info |
---|