[535] | 1 | ## Script (Python) "cpsdocument_edit" |
---|
| 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 | ## |
---|
[801] | 10 | # $Id: getStudentInfo.py 486 2006-09-06 10:09:39Z 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('/') |
---|
[563] | 21 | roles = member.getRoles() |
---|
[741] | 22 | |
---|
[535] | 23 | info = {} |
---|
[723] | 24 | info['is_manager'] = context.isManager() |
---|
[659] | 25 | info['is_student'] = context.isStudent() |
---|
[535] | 26 | member_id = str(member) |
---|
[645] | 27 | if student is None: |
---|
[787] | 28 | if mtool.isAnonymousUser(): |
---|
| 29 | return None |
---|
| 30 | elif context.isManager() 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() |
---|
[787] | 36 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
[785] | 37 | student = context.restrictedTraverse(student_path,default=None) |
---|
| 38 | if student is None or student.portal_type != 'Student': |
---|
[639] | 39 | return None |
---|
[785] | 40 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
| 41 | ##if not res:# or len(res) > 1: |
---|
| 42 | ## return None |
---|
| 43 | ##brain = res[-1] |
---|
| 44 | ##student = brain.getObject() |
---|
[742] | 45 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
[535] | 46 | info['student'] = student |
---|
[584] | 47 | info['id'] = student.getId() |
---|
[662] | 48 | info['url'] = student.absolute_url() |
---|
[538] | 49 | info['student_doc'] = student.getContent() |
---|
[535] | 50 | info['app'] = student.application |
---|
| 51 | info['app_doc'] = student.application.getContent() |
---|
| 52 | info['per'] = student.personal |
---|
| 53 | info['per_doc'] = student.personal.getContent() |
---|
[785] | 54 | course = getattr(student,'study_course',None) |
---|
| 55 | info['course'] = course |
---|
| 56 | if course: |
---|
| 57 | info['course_doc'] = student.study_course.getContent() |
---|
[635] | 58 | info['sex'] = 'male' |
---|
| 59 | if info['per_doc'].sex: |
---|
| 60 | info['sex'] = 'female' |
---|
[785] | 61 | ##res = context.portal_catalog(container_path=student_path, |
---|
| 62 | ## portal_type='StudentAccommodation') |
---|
| 63 | ##if res: |
---|
| 64 | ## acco = res[0].getObject() |
---|
| 65 | acco = getattr(student,'accommodation',None) |
---|
| 66 | if acco.portal_type != "StudentAccomodation": |
---|
| 67 | acco = None |
---|
| 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) |
---|
[785] | 72 | ##res = context.portal_catalog(container_path=student_path, |
---|
| 73 | ## portal_type='StudentClearance') |
---|
| 74 | ##if res: |
---|
| 75 | ## clear = res[0].getObject() |
---|
| 76 | ## info['clear'] = clear |
---|
| 77 | clear = getattr(student,'clearance',None) |
---|
| 78 | info['clear'] = clear |
---|
| 79 | if clear is not None: |
---|
[766] | 80 | info['clear_doc'] = clear.getContent() |
---|
| 81 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
[770] | 82 | |
---|
[785] | 83 | ##res = context.portal_catalog(container_path=student_path, |
---|
| 84 | ## portal_type='StudentPume') |
---|
| 85 | ##if res: |
---|
| 86 | ## pume = res[0].getObject() |
---|
| 87 | ## info['pume'] = clear |
---|
| 88 | pume = getattr(student,'pume',None) |
---|
| 89 | info['pume'] = pume |
---|
| 90 | if pume is not None: |
---|
[768] | 91 | info['pume_doc'] = pume.getContent() |
---|
| 92 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
| 93 | else: |
---|
[770] | 94 | info['pume'] = None |
---|
[659] | 95 | |
---|
| 96 | items = [] |
---|
[770] | 97 | s_edit_links = {'StudentApplication': 'application_edit', |
---|
[672] | 98 | 'StudentAccommodation': '', |
---|
[768] | 99 | 'StudentClearance': 'clearance_edit', |
---|
[672] | 100 | 'StudentPersonal': '', |
---|
| 101 | } |
---|
[770] | 102 | s_view_links = {'StudentApplication': 'application_view', |
---|
[748] | 103 | 'StudentAccommodation': 'accommodation_view', |
---|
[768] | 104 | 'StudentClearance': 'clearance_view', |
---|
[723] | 105 | 'StudentPersonal': None, |
---|
| 106 | 'StudentStudyCourse': 'study_course_view', |
---|
[768] | 107 | 'StudentPume': 'pume_view', |
---|
[674] | 108 | } |
---|
[659] | 109 | sos = context.portal_catalog(container_path=student_path) |
---|
[656] | 110 | for so in sos: |
---|
| 111 | row = {} |
---|
| 112 | soo = so.getObject() |
---|
| 113 | sod = soo.getContent() |
---|
| 114 | row['id'] = soo.getId() |
---|
| 115 | row['title'] = sod.Title() |
---|
| 116 | row['url'] = soo.absolute_url() |
---|
[659] | 117 | row['type'] = so.portal_type |
---|
[656] | 118 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
[739] | 119 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
[723] | 120 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
[674] | 121 | se_link = s_edit_links.get(so.portal_type,None) |
---|
| 122 | row['s_edit_link'] = None |
---|
| 123 | if se_link: |
---|
[767] | 124 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
[659] | 125 | row['review_state'] = so.review_state |
---|
[796] | 126 | row['display'] = so.review_state in ('opened','closed','public',) #or\ |
---|
| 127 | #so.portal_type in ("StudentAccommodation","StudentStudyCourse") |
---|
[656] | 128 | items.append(row) |
---|
| 129 | info['items'] = items |
---|
[742] | 130 | request.set('student_id',student_id) |
---|
| 131 | request.set('student_url',info['url']) |
---|
[535] | 132 | return info |
---|