## Script (Python) "changeCreditsInCourseResults" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=course_id,old_credits ##title= ## # $Id: changeCreditsInCourseResults.py 3129 2008-02-08 10:37:31Z henrik $ """ """ try: from Products.zdb import set_trace except: def set_trace(): pass mtool = context.portal_membership member = mtool.getAuthenticatedMember() if str(member) not in ('admin','joachim'): return import logging import DateTime logger = logging.getLogger('Skins.changeCreditsInCourseResults') from Products.AdvancedQuery import Eq, Between, Le,In aq_course_results = context.course_results.evalAdvancedQuery aq_courses_catalog = context.courses_catalog.evalAdvancedQuery request = context.REQUEST session = request.SESSION query = Eq('code',course_id) course_results = aq_course_results(query) edited = 0 wrong = 0 count = 0 commit_after = 50 course = context.courses_catalog.getRecordByKey(course_id) new_credits = course.credits #logger.info('started to change %d course_results credits from %s to %s' % # (len(course_results),old_credits,new_credits)) to_edit = [] for course_result in course_results: count += 1 if int(course_result.credits) != int(old_credits): logger.info("%s: credits %s does not match %s" % (course_result.key, course_result.credits, old_credits)) wrong += 1 continue to_edit += course_result.key, logger.info('%d %s course results found, start editing credits from %s to %s' % (len(course_results),course_id,old_credits,new_credits)) for key in to_edit: context.course_results.modifyRecord(**{'key': key, 'credits': int(new_credits)}) logger.info('finished editing %d %s course results, %d had wrong credits' % (count, course_id, wrong))