##parameters= # $Id: create_level_501.py 6858 2011-10-04 06:05:39Z henrik $ """ process the Application Form return html renderer + psm """ request = context.REQUEST import DateTime,logging try: from Products.zdb import set_trace except: def set_trace(): pass from Products.AdvancedQuery import Eq, Between, Le,In try: aq_portal = context.portal_catalog.evalAdvancedQuery except: aq_portal = context.portal_catalog_real.evalAdvancedQuery aq_courses = context.courses_catalog.evalAdvancedQuery aq_results = context.course_results.evalAdvancedQuery current = DateTime.DateTime() request = context.REQUEST response = request.RESPONSE redirect = response.redirect logger = logging.getLogger('Skins.create_level_501') info = context.waeup_tool.getAccessInfo(context) student_id = info['student_id'] if student_id is None: return None student = context.students_catalog.getRecordByKey(student_id) cert_id = student.course current_level = student.level if current_level not in ['500','510',]: logger.info('%s tried to create level 501 but is not in level 500' % student.id) return 'Forbidden' current_session = student.session in_progress = request.get('in_progress','not started') if aq_results(Eq('student_id',student_id) & Eq('level_id','100')): logger.info('%s tried to create already existing level 100' % student.id) return 'Forbidden' if context.hasObject('100') or context.hasObject('501'): logger.info('%s tried to create already existing level 100' % student.id) return 'Forbidden' context.invokeFactory('StudentStudyLevel',"%s" % '501') level = getattr(context,"501") context.portal_workflow.doActionFor(level,'open') level.getContent().edit(mapping={'session': current_session}) level_id = level.getId() session_id = context.getLevelSession(level.getContent(),student_id,level_id) results = [] records = [] l = [] res = context.portal_catalog(portal_type="Certificate", id = cert_id) if res: cert = res[0] path = cert.getPath() academics_level = '100' query = Eq("path","%s/%s" % (path,academics_level)) &\ Eq('portal_type','CertificateCourse') courses = aq_portal(query) for c in courses: course_id = "%s" % c.getId if course_id in l: # don't add twice continue l += course_id, d = context.getCourseInfo(c.getId) d['carry_over'] = False d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') d['course_id'] = course_id d['student_id'] = student_id = context.getStudentId() d['level_id'] = level_id d['session_id'] = session_id records.append(d) if records: existing_uids = context.course_results.addMultipleRecords(records) if existing_uids: logger.info('%s level 501 %s existing keys' % (student.id, ",".join(existing_uids))) logger.info('%s created level 501 (100 carry overs)' % student.id) return response.redirect("%s/501" % context.absolute_url())