[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 |
---|
[1048] | 7 | ##parameters=student=None, with_items=None |
---|
[535] | 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: getStudentInfo.py 1048 2006-12-13 18:11:26Z 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 | |
---|
[1006] | 22 | import logging |
---|
| 23 | logger = logging.getLogger('getStudentInfo') |
---|
| 24 | |
---|
[535] | 25 | info = {} |
---|
| 26 | member_id = str(member) |
---|
[1006] | 27 | #from Products.zdb import set_trace |
---|
| 28 | #set_trace() |
---|
| 29 | student_id = None |
---|
[645] | 30 | if student is None: |
---|
[1006] | 31 | while True: |
---|
| 32 | if mtool.isAnonymousUser(): |
---|
| 33 | return None |
---|
| 34 | try: |
---|
| 35 | requested_id = path_info[path_info.index('students')+1] |
---|
[1016] | 36 | except (ValueError,IndexError): |
---|
[1006] | 37 | student_id = member_id |
---|
| 38 | break |
---|
| 39 | if not context.isStudent() and 'students' in path_info: |
---|
| 40 | student_id = requested_id |
---|
| 41 | break |
---|
| 42 | if member_id != requested_id: |
---|
[1048] | 43 | logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id)) |
---|
[1006] | 44 | student_id = member_id |
---|
[1025] | 45 | mtool.assertViewable(context) |
---|
[1006] | 46 | break |
---|
[748] | 47 | student_id = member_id |
---|
[1006] | 48 | break |
---|
[645] | 49 | else: |
---|
| 50 | student_id = student.getId() |
---|
[1006] | 51 | |
---|
[1048] | 52 | #roles = member.getRoles() |
---|
[787] | 53 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
[785] | 54 | student = context.restrictedTraverse(student_path,default=None) |
---|
[971] | 55 | |
---|
[1006] | 56 | if student is None or student.portal_type != "Student": |
---|
[639] | 57 | return None |
---|
[785] | 58 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
| 59 | ##if not res:# or len(res) > 1: |
---|
| 60 | ## return None |
---|
| 61 | ##brain = res[-1] |
---|
| 62 | ##student = brain.getObject() |
---|
[742] | 63 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
[535] | 64 | info['student'] = student |
---|
[584] | 65 | info['id'] = student.getId() |
---|
[662] | 66 | info['url'] = student.absolute_url() |
---|
[538] | 67 | info['student_doc'] = student.getContent() |
---|
[535] | 68 | info['app'] = student.application |
---|
| 69 | info['app_doc'] = student.application.getContent() |
---|
[966] | 70 | info['per'] = getattr(student,'personal',None) |
---|
| 71 | info['sex'] = 'male' |
---|
| 72 | if info['per'] is not None: |
---|
| 73 | info['per_doc'] = student.personal.getContent() |
---|
| 74 | if info['per_doc'].sex: |
---|
| 75 | info['sex'] = 'female' |
---|
| 76 | else: |
---|
| 77 | if info['app_doc'].jamb_sex == "F": |
---|
| 78 | info['sex'] = 'female' |
---|
[785] | 79 | course = getattr(student,'study_course',None) |
---|
| 80 | if course: |
---|
[1025] | 81 | cert_id = course.getContent().study_course |
---|
| 82 | res = context.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
| 83 | ci = {} |
---|
| 84 | if len(res) > 0: |
---|
| 85 | info['course'] = course |
---|
| 86 | brain = res[0] |
---|
| 87 | ci['study_course'] = brain.getId |
---|
| 88 | ci['title'] = brain.Title |
---|
| 89 | pl = brain.getPath().split('/') |
---|
| 90 | ci['faculty'] = pl[-4] |
---|
| 91 | ci['department'] = pl[-3] |
---|
| 92 | info['course_doc'] = ci |
---|
| 93 | else: |
---|
| 94 | info['course'] = None |
---|
[867] | 95 | # |
---|
[812] | 96 | acco = getattr(student,'accommodation_2006',None) |
---|
[785] | 97 | info['acco'] = acco |
---|
| 98 | if acco is not None: |
---|
[639] | 99 | info['acco_doc'] = acco.getContent() |
---|
[748] | 100 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
[867] | 101 | # |
---|
[785] | 102 | clear = getattr(student,'clearance',None) |
---|
| 103 | info['clear'] = clear |
---|
| 104 | if clear is not None: |
---|
[766] | 105 | info['clear_doc'] = clear.getContent() |
---|
| 106 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
[867] | 107 | # |
---|
[785] | 108 | pume = getattr(student,'pume',None) |
---|
| 109 | info['pume'] = pume |
---|
| 110 | if pume is not None: |
---|
[768] | 111 | info['pume_doc'] = pume.getContent() |
---|
| 112 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
| 113 | else: |
---|
[770] | 114 | info['pume'] = None |
---|
[659] | 115 | |
---|
| 116 | items = [] |
---|
[803] | 117 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
[814] | 118 | 'StudentAccommodation': 'reserve_accommodation', |
---|
[803] | 119 | 'StudentClearance': 'clearance_edit_form', |
---|
[672] | 120 | 'StudentPersonal': '', |
---|
| 121 | } |
---|
[770] | 122 | s_view_links = {'StudentApplication': 'application_view', |
---|
[748] | 123 | 'StudentAccommodation': 'accommodation_view', |
---|
[768] | 124 | 'StudentClearance': 'clearance_view', |
---|
[723] | 125 | 'StudentPersonal': None, |
---|
| 126 | 'StudentStudyCourse': 'study_course_view', |
---|
[768] | 127 | 'StudentPume': 'pume_view', |
---|
[674] | 128 | } |
---|
[1048] | 129 | if not with_items: |
---|
| 130 | return info |
---|
[659] | 131 | sos = context.portal_catalog(container_path=student_path) |
---|
[656] | 132 | for so in sos: |
---|
| 133 | row = {} |
---|
| 134 | soo = so.getObject() |
---|
| 135 | sod = soo.getContent() |
---|
| 136 | row['id'] = soo.getId() |
---|
| 137 | row['title'] = sod.Title() |
---|
| 138 | row['url'] = soo.absolute_url() |
---|
[659] | 139 | row['type'] = so.portal_type |
---|
[656] | 140 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
[739] | 141 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
[723] | 142 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
[674] | 143 | se_link = s_edit_links.get(so.portal_type,None) |
---|
| 144 | row['s_edit_link'] = None |
---|
| 145 | if se_link: |
---|
[767] | 146 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
[659] | 147 | row['review_state'] = so.review_state |
---|
[1032] | 148 | row['display'] = so.review_state in ('opened','closed',) or so.portal_type == 'StudentStudyCourse' |
---|
[656] | 149 | items.append(row) |
---|
| 150 | info['items'] = items |
---|
[742] | 151 | request.set('student_id',student_id) |
---|
| 152 | request.set('student_url',info['url']) |
---|
[535] | 153 | return info |
---|