## Script (Python) "refresh_level" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None # $Id: refresh_level.py 2460 2007-10-28 14:46:29Z joachim $ """ 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 import logging logger = logging.getLogger('Skins.refresh_level') from urllib import urlencode current = DateTime.DateTime() request = context.REQUEST #session = request.SESSION response = request.RESPONSE redirect = response.redirect logger = logging.getLogger('Skins.refresh_level') mtool = context.portal_membership member = mtool.getAuthenticatedMember() member_id = str(member) wt = context.waeup_tool student = context.students_catalog(id=context.getStudentId())[0] cert_id = student.course student_id = context.getStudentId() level = context level_id = context.getId() res = context.portal_catalog(portal_type="Certificate", id = cert_id) query = Eq('student_id',student_id) & Eq('level_id', level_id) existing_courses = [course.code for course in context.course_results.evalAdvancedQuery(query)] l = [] records = [] if res: cert = res[0] path = cert.getPath() query = Eq("path","%s/%s" % (path,student.level)) &\ Eq('portal_type','CertificateCourse') courses = aq_portal(query) course_ids = [c.getId for c in courses if c.getId not in existing_courses] for course_id in course_ids: #set_trace() if course_id in l: # don't add twice continue l += course_id, d = context.getCourseInfo(course_id) d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') d['course_id'] = course_id d['student_id'] = student_id d['level_id'] = level_id d['key'] = "%s|%s|%s" % (student_id,level_id,course_id) records.append(d) if records: context.course_results.addMultipleRecords(records) #session.set('in_progress','finished') logger.info('%s updated course list' % member) args = {} psm = "Course list updated!" args['portal_status_message'] = psm if action_after_validate: url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) else: url = context.absolute_url() + '?' + urlencode(args) return REQUEST.RESPONSE.redirect(url)