1 | ##parameters= |
---|
2 | # $Id: create_level_101.py 6863 2011-10-05 06:46:03Z 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_101') |
---|
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 | current_session = student.session |
---|
37 | in_progress = request.get('in_progress','not started') |
---|
38 | if aq_results(Eq('student_id',student_id) & Eq('level_id','100')): |
---|
39 | logger.info('%s tried to create already existing level 100' % student.id) |
---|
40 | return 'Forbidden' |
---|
41 | |
---|
42 | if context.hasObject('100') or context.hasObject('101'): |
---|
43 | logger.info('%s tried to create already existing level 100' % student.id) |
---|
44 | return 'Forbidden' |
---|
45 | |
---|
46 | context.invokeFactory('StudentStudyLevel',"%s" % '101') |
---|
47 | level = getattr(context,"101") |
---|
48 | context.portal_workflow.doActionFor(level,'open') |
---|
49 | level.getContent().edit(mapping={'session': current_session}) |
---|
50 | level_id = level.getId() |
---|
51 | session_id = context.getLevelSession(level.getContent(),student_id,level_id) |
---|
52 | results = [] |
---|
53 | records = [] |
---|
54 | l = [] |
---|
55 | |
---|
56 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
57 | if res: |
---|
58 | cert = res[0] |
---|
59 | path = cert.getPath() |
---|
60 | academics_level = '100' |
---|
61 | query = Eq("path","%s/%s" % (path,academics_level)) &\ |
---|
62 | Eq('portal_type','CertificateCourse') |
---|
63 | courses = aq_portal(query) |
---|
64 | for c in courses: |
---|
65 | course_id = "%s" % c.getId |
---|
66 | if course_id in l: |
---|
67 | # don't add twice |
---|
68 | continue |
---|
69 | l += course_id, |
---|
70 | d = context.getCourseInfo(c.getId) |
---|
71 | d['carry_over'] = False |
---|
72 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
73 | d['course_id'] = course_id |
---|
74 | d['student_id'] = student_id = context.getStudentId() |
---|
75 | d['level_id'] = level_id |
---|
76 | d['session_id'] = session_id |
---|
77 | records.append(d) |
---|
78 | |
---|
79 | if records: |
---|
80 | existing_uids = context.course_results.addMultipleRecords(records) |
---|
81 | if existing_uids: |
---|
82 | logger.info('%s level 101 %s existing keys' % (student.id, |
---|
83 | ",".join(existing_uids))) |
---|
84 | |
---|
85 | logger.info('%s created level 101 (100 carryovers)' % student.id) |
---|
86 | |
---|
87 | return response.redirect("%s/101" % context.absolute_url()) |
---|