## Script (Python) "ti_385_resolve" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: moveCourseResults.py 2602 2007-11-09 07:54:15Z 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.moveCourseResults') from Products.AdvancedQuery import Eq, Between, Le,In aq_results = context.course_results.evalAdvancedQuery aq_students = context.students_catalog.evalAdvancedQuery students = 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) #logger.info('') brains = aq_students(In('review_state',('courses_registered','courses_validated'))) total = len(brains) logger.info("found %d students" % (total)) count = 0 moved = 0 cocount = 0 commit_after = 20 moved_sids = context.course_results.uniqueValuesFor('student_id') for brain in brains: count += 1 if brain.id in moved_sids: continue try: study_level = getattr(getattr(getattr(students,brain.id), "study_course") ,brain.level) results = study_level.objectIds() except: #rwrite('not found %s/study_course/%s' % (brain.id,brain.level)) continue if not results: continue #rwrite('no result objects in %s/study_course/%s' % (brain.id,brain.level)) else: #logger.info("moving results of student %s" % (brain.id)) context.course_results.moveResultsHere(study_level,brain.id) moved += 1 logger.info("moved results of student %s" % (brain.id)) if moved and not moved % commit_after: context.waeup_tool.doCommit() logger.info("Committing %s transactions, total %s" % (commit_after,count)) #cocount += 1 #if cocount > 2: # break msg = "finished moving results of %d students" % (moved) logger.info(msg) #rwrite(msg)