## Script (Python) "ti_71fc_resolve" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: ti_71fc_resolve.py 3084 2008-02-01 12:15:11Z joachim $ """ """ 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') from Products.AdvancedQuery import Eq, Between, Le,In aq_students = context.students_catalog.evalAdvancedQuery aq_portal = context.portal_catalog_real.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") # query = In('level',levels_to_look_for) # student_records = aq_students(query) # logger.info('found %d students with levels %s' % (len(student_records), " ".join(levels_to_look_for))) # students = {} # for student_record in student_records: # students[student_record.id] = student_record.level query = In('id',levels_to_look_for) & Eq('portal_type','StudentStudyLevel') levels= aq_portal(query) logger.info('found %d students with levels %s' % (len(levels), " ".join(levels_to_look_for))) students = {} for level in levels: student_id = level.getPath().split('/')[-3] students[student_id] = level.getId for student_id,level in students.items(): study_course = getattr(getattr(students_folder,student_id),'study_course',None) if study_course is None: logger.info('%s study_course not found' % (student_record.id)) continue #logger.info('%s renaming level' % (student_id)) if level == '110': if hasattr(study_course,'110'): study_course.manage_renameObjects(('110',),('200',)) logger.info('%s renamed level from 110 to 200' % (student_id)) else: logger.info('%s no level-object for 110' % (student_id)) elif level == '210': if hasattr(study_course,'210'): study_course.manage_renameObjects(('210',),('300',)) logger.info('%s renamed level from 110 to 200' % (student_id)) else: logger.info('%s no level-object for 210' % (student_id)) logger.info('finished')