1 | ## Script (Python) "getClearanceInfo" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getClearanceInfo.py 1596 2007-03-19 21:45:44Z joachim $ |
---|
11 | """ |
---|
12 | return Info about the current Student |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Skins.getClearanceInfo') |
---|
16 | from DateTime import DateTime |
---|
17 | |
---|
18 | request = context.REQUEST |
---|
19 | mtool = context.portal_membership |
---|
20 | wf = context.portal_workflow |
---|
21 | member = mtool.getAuthenticatedMember() |
---|
22 | member_id = str(member) |
---|
23 | path_info = request.get('PATH_INFO').split('/') |
---|
24 | |
---|
25 | if mtool.isAnonymousUser(): |
---|
26 | return None |
---|
27 | info = {} |
---|
28 | #from Products.zdb import set_trace |
---|
29 | #set_trace() |
---|
30 | requested_id = context.getStudentId() |
---|
31 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
32 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
33 | return None |
---|
34 | elif context.isStaff(): |
---|
35 | student_id = requested_id |
---|
36 | else: |
---|
37 | student_id = member_id |
---|
38 | |
---|
39 | |
---|
40 | students_object = context.portal_url.getPortalObject().campus.students |
---|
41 | student = getattr(students_object, student_id) |
---|
42 | res = context.portal_catalog(portal_type='Student',id = student_id) |
---|
43 | if len(res) == 0: |
---|
44 | return None |
---|
45 | creation_date = DateTime(res[0].CreationDate) |
---|
46 | info['penalty'] = creation_date.lessThan(DateTime('2006/12/5')) |
---|
47 | info['id'] = student_id |
---|
48 | info['student'] = student |
---|
49 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
50 | info['app'] = student.application |
---|
51 | info['app_doc'] = student.application.getContent() |
---|
52 | info['clear'] = student.clearance |
---|
53 | info['clear_doc'] = student.clearance.getContent() |
---|
54 | info['clear_review_state'] = wf.getInfoFor(student.clearance,'review_state',None) |
---|
55 | if info['review_state'] in ('clearance_requested', 'cleared_and_validated',): |
---|
56 | info['penalty'] = info['penalty'] and\ |
---|
57 | info['clear_doc'].entry_date.greaterThan(DateTime('2006/12/30')) |
---|
58 | course = getattr(student,'study_course',None) |
---|
59 | if course: |
---|
60 | cert_id = course.getContent().study_course |
---|
61 | res = context.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
62 | ci = {} |
---|
63 | if len(res) > 0: |
---|
64 | info['course'] = course |
---|
65 | brain = res[0] |
---|
66 | ci['study_course'] = brain.getId |
---|
67 | ci['title'] = brain.Title |
---|
68 | pl = brain.getPath().split('/') |
---|
69 | ci['faculty'] = pl[-4] |
---|
70 | ci['department'] = pl[-3] |
---|
71 | info['course_doc'] = ci |
---|
72 | else: |
---|
73 | info['course'] = None |
---|
74 | return info |
---|