[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 903 2006-11-20 08:08:10Z henrik $ |
---|
[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 = {} |
---|
[903] | 23 | info['is_manager'] = context.isSectionManager() |
---|
[659] | 24 | info['is_student'] = context.isStudent() |
---|
[894] | 25 | info['is_co'] = context.isClearanceOfficer() |
---|
[535] | 26 | member_id = str(member) |
---|
[645] | 27 | if student is None: |
---|
[787] | 28 | if mtool.isAnonymousUser(): |
---|
| 29 | return None |
---|
[885] | 30 | elif not context.isStudent() and 'students' in path_info: |
---|
[741] | 31 | student_id = path_info[path_info.index('students')+1] |
---|
[646] | 32 | else: |
---|
[748] | 33 | student_id = member_id |
---|
[645] | 34 | else: |
---|
| 35 | student_id = student.getId() |
---|
[883] | 36 | roles = member.getRoles() |
---|
[787] | 37 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
[785] | 38 | student = context.restrictedTraverse(student_path,default=None) |
---|
| 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() |
---|
| 53 | info['per'] = student.personal |
---|
| 54 | info['per_doc'] = student.personal.getContent() |
---|
[785] | 55 | course = getattr(student,'study_course',None) |
---|
[867] | 56 | # |
---|
[785] | 57 | info['course'] = course |
---|
| 58 | if course: |
---|
| 59 | info['course_doc'] = student.study_course.getContent() |
---|
[635] | 60 | info['sex'] = 'male' |
---|
| 61 | if info['per_doc'].sex: |
---|
| 62 | info['sex'] = 'female' |
---|
[867] | 63 | # |
---|
[812] | 64 | acco = getattr(student,'accommodation_2006',None) |
---|
[785] | 65 | info['acco'] = acco |
---|
| 66 | if acco is not None: |
---|
[639] | 67 | info['acco_doc'] = acco.getContent() |
---|
[748] | 68 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
[867] | 69 | # |
---|
[785] | 70 | clear = getattr(student,'clearance',None) |
---|
| 71 | info['clear'] = clear |
---|
| 72 | if clear is not None: |
---|
[766] | 73 | info['clear_doc'] = clear.getContent() |
---|
| 74 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
[867] | 75 | # |
---|
[785] | 76 | pume = getattr(student,'pume',None) |
---|
| 77 | info['pume'] = pume |
---|
| 78 | if pume is not None: |
---|
[768] | 79 | info['pume_doc'] = pume.getContent() |
---|
| 80 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
| 81 | else: |
---|
[770] | 82 | info['pume'] = None |
---|
[659] | 83 | |
---|
| 84 | items = [] |
---|
[803] | 85 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
[814] | 86 | 'StudentAccommodation': 'reserve_accommodation', |
---|
[803] | 87 | 'StudentClearance': 'clearance_edit_form', |
---|
[672] | 88 | 'StudentPersonal': '', |
---|
| 89 | } |
---|
[770] | 90 | s_view_links = {'StudentApplication': 'application_view', |
---|
[748] | 91 | 'StudentAccommodation': 'accommodation_view', |
---|
[768] | 92 | 'StudentClearance': 'clearance_view', |
---|
[723] | 93 | 'StudentPersonal': None, |
---|
| 94 | 'StudentStudyCourse': 'study_course_view', |
---|
[768] | 95 | 'StudentPume': 'pume_view', |
---|
[674] | 96 | } |
---|
[659] | 97 | sos = context.portal_catalog(container_path=student_path) |
---|
[656] | 98 | for so in sos: |
---|
| 99 | row = {} |
---|
| 100 | soo = so.getObject() |
---|
| 101 | sod = soo.getContent() |
---|
| 102 | row['id'] = soo.getId() |
---|
| 103 | row['title'] = sod.Title() |
---|
| 104 | row['url'] = soo.absolute_url() |
---|
[659] | 105 | row['type'] = so.portal_type |
---|
[656] | 106 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
[739] | 107 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
[723] | 108 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
[674] | 109 | se_link = s_edit_links.get(so.portal_type,None) |
---|
| 110 | row['s_edit_link'] = None |
---|
| 111 | if se_link: |
---|
[767] | 112 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
[659] | 113 | row['review_state'] = so.review_state |
---|
[849] | 114 | row['display'] = so.review_state in ('opened','closed',) |
---|
[656] | 115 | items.append(row) |
---|
| 116 | info['items'] = items |
---|
[742] | 117 | request.set('student_id',student_id) |
---|
| 118 | request.set('student_url',info['url']) |
---|
[535] | 119 | return info |
---|