## Script (Python) "reindexCourseCatalog" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST ##title= ## # $Id: reindexCoursesCatalog.py 1596 2007-03-19 21:45:44Z joachim $ """ list Students for ClearanceOfficers """ try: from Products.zdb import set_trace except: def set_trace(): pass request = context.REQUEST session = request.SESSION response = request.RESPONSE setheader = request.RESPONSE.setHeader import logging logger = logging.getLogger('Skins.reindexCourseCatalog') def rwrite(s): response.setHeader('Content-type','text/html; charset=ISO-8859-15') response.write(s) mtool = context.portal_membership member = mtool.getAuthenticatedMember() #students_cat = context.students_catalog courses_cat = context.courses_catalog from Products.AdvancedQuery import Eq, Between, Le,In #aq_students = students_cat.evalAdvancedQuery aq_portal = context.portal_catalog.evalAdvancedQuery students = context.portal_url.getPortalObject().campus.students count = 0 ##query = Eq('portal_type','Student') & In('review_state',('admitted', ## 'clearance_requested', ## 'cleared_and_validated', ## 'objection_raised', ## ) ##res = aq_portal(query) query = Eq('portal_type','Course') courses = aq_portal(query) #set_trace() count = 0 count_full = 0 commit_count = 0 logger.info("Reindexing of courses_catalog started for %s courses" % len(courses)) for course_brain in courses: course_doc = course_brain.getObject().getContent() d = {} d['code'] = getattr(course_doc,'code') d['credits'] = getattr(course_doc,'credits') d['level'] = getattr(course_doc,'level') d['passmark'] = getattr(course_doc,'passmark') d['semester'] = getattr(course_doc,'semester') d['title'] = getattr(course_doc,'title') pl = course_brain.getPath().split('/') d['faculty'] = pl[-4] d['department'] = pl[-3] try: courses_cat.modifyRecord(**d) except KeyError: courses_cat.addRecord(**d) count += 1 commit_count += 1 if commit_count > 1000: context.waeup_tool.doCommit() logger.info("Committing %s transactions, total %s" % (commit_count,count)) rwrite("%s: committed %s
" % (count,commit_count)) commit_count = 0 rwrite("finished") logger.info("Reindexing finished (%s courses)" % count)