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