source: WAeUP_SRP/trunk/skins/waeup_futminna/create_level_101.py @ 16595

Last change on this file since 16595 was 6863, checked in by Henrik Bettermann, 13 years ago

carryover not carry over

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1##parameters=
2# $Id: create_level_101.py 6863 2011-10-05 06:46:03Z henrik $
3"""
4process the Application Form
5return html renderer + psm
6"""
7request = context.REQUEST
8import DateTime,logging
9try:
10    from Products.zdb import set_trace
11except:
12    def set_trace():
13        pass
14from Products.AdvancedQuery import Eq, Between, Le,In
15try:
16    aq_portal = context.portal_catalog.evalAdvancedQuery
17except:
18    aq_portal = context.portal_catalog_real.evalAdvancedQuery
19aq_courses = context.courses_catalog.evalAdvancedQuery
20aq_results = context.course_results.evalAdvancedQuery
21
22current = DateTime.DateTime()
23request = context.REQUEST
24response = request.RESPONSE
25redirect = response.redirect
26logger = logging.getLogger('Skins.create_level_101')
27info = context.waeup_tool.getAccessInfo(context)
28student_id = info['student_id']
29if student_id is None:
30    return None
31
32student = context.students_catalog.getRecordByKey(student_id)
33cert_id = student.course
34current_level = student.level
35
36current_session = student.session
37in_progress =  request.get('in_progress','not started')
38if 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
42if context.hasObject('100') or context.hasObject('101'):
43    logger.info('%s tried to create already existing level 100' % student.id)
44    return 'Forbidden'
45
46context.invokeFactory('StudentStudyLevel',"%s" % '101')
47level = getattr(context,"101")
48context.portal_workflow.doActionFor(level,'open')
49level.getContent().edit(mapping={'session': current_session})
50level_id = level.getId()
51session_id = context.getLevelSession(level.getContent(),student_id,level_id)
52results = []
53records = []
54l = []
55
56res = context.portal_catalog(portal_type="Certificate", id = cert_id)
57if 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
79if 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
85logger.info('%s created level 101 (100 carryovers)' % student.id)
86
87return response.redirect("%s/101" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.