1 | ##parameters= |
---|
2 | # $Id: create_level_501.py 6858 2011-10-04 06:05:39Z henrik $ |
---|
3 | """ |
---|
4 | process the Application Form |
---|
5 | return html renderer + psm |
---|
6 | """ |
---|
7 | request = context.REQUEST |
---|
8 | import DateTime,logging |
---|
9 | try: |
---|
10 | from Products.zdb import set_trace |
---|
11 | except: |
---|
12 | def set_trace(): |
---|
13 | pass |
---|
14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
15 | try: |
---|
16 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
17 | except: |
---|
18 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
19 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
20 | aq_results = context.course_results.evalAdvancedQuery |
---|
21 | |
---|
22 | current = DateTime.DateTime() |
---|
23 | request = context.REQUEST |
---|
24 | response = request.RESPONSE |
---|
25 | redirect = response.redirect |
---|
26 | logger = logging.getLogger('Skins.create_level_501') |
---|
27 | info = context.waeup_tool.getAccessInfo(context) |
---|
28 | student_id = info['student_id'] |
---|
29 | if student_id is None: |
---|
30 | return None |
---|
31 | |
---|
32 | student = context.students_catalog.getRecordByKey(student_id) |
---|
33 | cert_id = student.course |
---|
34 | current_level = student.level |
---|
35 | |
---|
36 | if current_level not in ['500','510',]: |
---|
37 | logger.info('%s tried to create level 501 but is not in level 500' % student.id) |
---|
38 | return 'Forbidden' |
---|
39 | |
---|
40 | current_session = student.session |
---|
41 | in_progress = request.get('in_progress','not started') |
---|
42 | if aq_results(Eq('student_id',student_id) & Eq('level_id','100')): |
---|
43 | logger.info('%s tried to create already existing level 100' % student.id) |
---|
44 | return 'Forbidden' |
---|
45 | |
---|
46 | if context.hasObject('100') or context.hasObject('501'): |
---|
47 | logger.info('%s tried to create already existing level 100' % student.id) |
---|
48 | return 'Forbidden' |
---|
49 | |
---|
50 | context.invokeFactory('StudentStudyLevel',"%s" % '501') |
---|
51 | level = getattr(context,"501") |
---|
52 | context.portal_workflow.doActionFor(level,'open') |
---|
53 | level.getContent().edit(mapping={'session': current_session}) |
---|
54 | level_id = level.getId() |
---|
55 | session_id = context.getLevelSession(level.getContent(),student_id,level_id) |
---|
56 | results = [] |
---|
57 | records = [] |
---|
58 | l = [] |
---|
59 | |
---|
60 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
61 | if res: |
---|
62 | cert = res[0] |
---|
63 | path = cert.getPath() |
---|
64 | academics_level = '100' |
---|
65 | query = Eq("path","%s/%s" % (path,academics_level)) &\ |
---|
66 | Eq('portal_type','CertificateCourse') |
---|
67 | courses = aq_portal(query) |
---|
68 | for c in courses: |
---|
69 | course_id = "%s" % c.getId |
---|
70 | if course_id in l: |
---|
71 | # don't add twice |
---|
72 | continue |
---|
73 | l += course_id, |
---|
74 | d = context.getCourseInfo(c.getId) |
---|
75 | d['carry_over'] = False |
---|
76 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
77 | d['course_id'] = course_id |
---|
78 | d['student_id'] = student_id = context.getStudentId() |
---|
79 | d['level_id'] = level_id |
---|
80 | d['session_id'] = session_id |
---|
81 | records.append(d) |
---|
82 | |
---|
83 | if records: |
---|
84 | existing_uids = context.course_results.addMultipleRecords(records) |
---|
85 | if existing_uids: |
---|
86 | logger.info('%s level 501 %s existing keys' % (student.id, |
---|
87 | ",".join(existing_uids))) |
---|
88 | |
---|
89 | logger.info('%s created level 501 (100 carry overs)' % student.id) |
---|
90 | |
---|
91 | return response.redirect("%s/501" % context.absolute_url()) |
---|