[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 2043 2007-07-21 18:53:04Z 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 |
---|
[1571] | 23 | logger = logging.getLogger('Skins.getStudentInfo') |
---|
[1006] | 24 | |
---|
[1144] | 25 | |
---|
[535] | 26 | info = {} |
---|
| 27 | member_id = str(member) |
---|
[1006] | 28 | #from Products.zdb import set_trace |
---|
| 29 | #set_trace() |
---|
| 30 | student_id = None |
---|
[645] | 31 | if student is None: |
---|
[1006] | 32 | while True: |
---|
| 33 | if mtool.isAnonymousUser(): |
---|
| 34 | return None |
---|
| 35 | try: |
---|
| 36 | requested_id = path_info[path_info.index('students')+1] |
---|
[1016] | 37 | except (ValueError,IndexError): |
---|
[1006] | 38 | student_id = member_id |
---|
| 39 | break |
---|
| 40 | if not context.isStudent() and 'students' in path_info: |
---|
| 41 | student_id = requested_id |
---|
| 42 | break |
---|
| 43 | if member_id != requested_id: |
---|
[1571] | 44 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
[1006] | 45 | student_id = member_id |
---|
[1025] | 46 | mtool.assertViewable(context) |
---|
[1006] | 47 | break |
---|
[748] | 48 | student_id = member_id |
---|
[1006] | 49 | break |
---|
[645] | 50 | else: |
---|
| 51 | student_id = student.getId() |
---|
[1006] | 52 | |
---|
[1048] | 53 | #roles = member.getRoles() |
---|
[787] | 54 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
[785] | 55 | student = context.restrictedTraverse(student_path,default=None) |
---|
[971] | 56 | |
---|
[1006] | 57 | if student is None or student.portal_type != "Student": |
---|
[639] | 58 | return None |
---|
[785] | 59 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
| 60 | ##if not res:# or len(res) > 1: |
---|
| 61 | ## return None |
---|
| 62 | ##brain = res[-1] |
---|
| 63 | ##student = brain.getObject() |
---|
[1144] | 64 | |
---|
[1871] | 65 | info['review_state'] = context.getStudentReviewState() |
---|
[535] | 66 | info['student'] = student |
---|
[584] | 67 | info['id'] = student.getId() |
---|
[662] | 68 | info['url'] = student.absolute_url() |
---|
[538] | 69 | info['student_doc'] = student.getContent() |
---|
[1179] | 70 | info['app'] = student.application |
---|
| 71 | info['app_doc'] = student.application.getContent() |
---|
[1171] | 72 | #info['per'] = getattr(student,'personal',None) |
---|
| 73 | #info['sex'] = 'male' |
---|
| 74 | #if info['per'] is not None: |
---|
| 75 | # info['per_doc'] = student.personal.getContent() |
---|
| 76 | # if info['per_doc'].sex: |
---|
| 77 | # info['sex'] = 'female' |
---|
| 78 | #else: |
---|
| 79 | # if info['app_doc'].jamb_sex == "F": |
---|
| 80 | # info['sex'] = 'female' |
---|
[785] | 81 | course = getattr(student,'study_course',None) |
---|
| 82 | if course: |
---|
[1025] | 83 | cert_id = course.getContent().study_course |
---|
| 84 | res = context.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
| 85 | ci = {} |
---|
| 86 | if len(res) > 0: |
---|
| 87 | info['course'] = course |
---|
| 88 | brain = res[0] |
---|
| 89 | ci['study_course'] = brain.getId |
---|
| 90 | ci['title'] = brain.Title |
---|
| 91 | pl = brain.getPath().split('/') |
---|
| 92 | ci['faculty'] = pl[-4] |
---|
| 93 | ci['department'] = pl[-3] |
---|
| 94 | info['course_doc'] = ci |
---|
| 95 | else: |
---|
| 96 | info['course'] = None |
---|
[867] | 97 | # |
---|
[2043] | 98 | |
---|
| 99 | #clear = getattr(student,'clearance',None) |
---|
| 100 | #info['clear'] = clear |
---|
| 101 | #if clear is not None: |
---|
| 102 | # info['clear_doc'] = clear.getContent() |
---|
| 103 | # info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
[867] | 104 | # |
---|
[2043] | 105 | #pume = getattr(student,'pume',None) |
---|
| 106 | #info['pume'] = pume |
---|
| 107 | #if pume is not None: |
---|
| 108 | # info['pume_doc'] = pume.getContent() |
---|
| 109 | # info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
| 110 | #else: |
---|
| 111 | # info['pume'] = None |
---|
[659] | 112 | |
---|
[1067] | 113 | if not with_items: |
---|
| 114 | return info |
---|
| 115 | |
---|
[742] | 116 | request.set('student_id',student_id) |
---|
| 117 | request.set('student_url',info['url']) |
---|
[535] | 118 | return info |
---|