source: WAeUP_SRP/trunk/skins/waeup_futminna/create_level_501.py @ 6858

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

Implement 100L carryover courses registration in current_level 100. The level id is 501. The course result records are not beeing marked as carryovers because students can add courses which are not marked as such.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1##parameters=
2# $Id: create_level_501.py 6858 2011-10-04 06:05:39Z 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_501')
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
36if 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
40current_session = student.session
41in_progress =  request.get('in_progress','not started')
42if 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
46if context.hasObject('100') or context.hasObject('501'):
47    logger.info('%s tried to create already existing level 100' % student.id)
48    return 'Forbidden'
49
50context.invokeFactory('StudentStudyLevel',"%s" % '501')
51level = getattr(context,"501")
52context.portal_workflow.doActionFor(level,'open')
53level.getContent().edit(mapping={'session': current_session})
54level_id = level.getId()
55session_id = context.getLevelSession(level.getContent(),student_id,level_id)
56results = []
57records = []
58l = []
59
60res = context.portal_catalog(portal_type="Certificate", id = cert_id)
61if 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
83if 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
89logger.info('%s created level 501 (100 carry overs)' % student.id)
90
91return response.redirect("%s/501" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.