1 | ## Script (Python) "getStudentInfo" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=student=None, with_items=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getStudentInfo.py 2407 2007-10-21 06:21:25Z henrik $ |
---|
11 | """ |
---|
12 | return Info about the current Student |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | form = request.form |
---|
16 | fget = form.get |
---|
17 | wf = context.portal_workflow |
---|
18 | mtool = context.portal_membership |
---|
19 | member = mtool.getAuthenticatedMember() |
---|
20 | path_info = request.get('PATH_INFO').split('/') |
---|
21 | |
---|
22 | import logging |
---|
23 | logger = logging.getLogger('Skins.getStudentInfo') |
---|
24 | |
---|
25 | |
---|
26 | info = {} |
---|
27 | member_id = str(member) |
---|
28 | #from Products.zdb import set_trace |
---|
29 | #set_trace() |
---|
30 | student_id = None |
---|
31 | if student is None: |
---|
32 | while True: |
---|
33 | if mtool.isAnonymousUser(): |
---|
34 | return None |
---|
35 | try: |
---|
36 | requested_id = path_info[path_info.index('students')+1] |
---|
37 | except (ValueError,IndexError): |
---|
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: |
---|
44 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
45 | student_id = member_id |
---|
46 | mtool.assertViewable(context) |
---|
47 | break |
---|
48 | student_id = member_id |
---|
49 | break |
---|
50 | else: |
---|
51 | student_id = student.getId() |
---|
52 | |
---|
53 | #roles = member.getRoles() |
---|
54 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
55 | student = context.restrictedTraverse(student_path,default=None) |
---|
56 | |
---|
57 | if student is None or student.portal_type != "Student": |
---|
58 | return None |
---|
59 | |
---|
60 | info['review_state'] = context.getStudentReviewState() |
---|
61 | info['student'] = student |
---|
62 | info['id'] = student.getId() |
---|
63 | info['url'] = student.absolute_url() |
---|
64 | info['student_doc'] = student.getContent() |
---|
65 | info['app'] = student.application |
---|
66 | info['app_doc'] = student.application.getContent() |
---|
67 | |
---|
68 | course = getattr(student,'study_course',None) |
---|
69 | if course: |
---|
70 | cert_id = course.getContent().study_course |
---|
71 | res = context.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
72 | ci = {} |
---|
73 | if len(res) > 0: |
---|
74 | info['course'] = course |
---|
75 | brain = res[0] |
---|
76 | ci['study_course'] = brain.getId |
---|
77 | ci['title'] = brain.Title |
---|
78 | pl = brain.getPath().split('/') |
---|
79 | ci['faculty'] = pl[-4] |
---|
80 | ci['department'] = pl[-3] |
---|
81 | info['course_doc'] = ci |
---|
82 | else: |
---|
83 | info['course'] = None |
---|
84 | |
---|
85 | if not with_items: |
---|
86 | return info |
---|
87 | |
---|
88 | request.set('student_id',student_id) |
---|
89 | request.set('student_url',info['url']) |
---|
90 | return info |
---|