## Script (Python) "ti_71fc_resolve_fix" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: ti_71fc_resolve_fix.py 3159 2008-02-13 20:13:28Z 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.ti_71fc_resolve_fix') from Products.AdvancedQuery import Eq, Between, Le,In aq_students = context.students_catalog.evalAdvancedQuery aq_portal = context.portal_catalog_real.evalAdvancedQuery course_results = context.course_results aq_course_results = course_results.evalAdvancedQuery students_folder = context.portal_url.getPortalObject().campus.students request = context.REQUEST session = request.SESSION response = request.RESPONSE setheader = request.RESPONSE.setHeader def rwrite(s): response.setHeader('Content-type','text/html; charset=ISO-8859-15') response.write("%s
\n\r" % s) levels_to_look_for = ("110","210") course_results_to_change = [] for result in course_results(): student_id,level_id,code = result.key.split('|') if code != result.code: d = {} for field in course_results.schema(): d[field] = getattr(result,field) d['old_key'] = d['key'] d['key'] = "%s|%s|%s" % (student_id,result.level_id,result.code) course_results_to_change += d, for result in course_results_to_change: try: course_results.addRecord(**result) logger.info('%(student_id)s adding %(key)s' % result) except ValueError: set_trace() logger.info('%(student_id)s %(key)s already there' % result) logger.info('%(student_id)s deleting %(old_key)s' % result) course_results.deleteRecord(result['old_key']) logger.info('finished')