## Script (Python) "reindex_entry_mode" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: reindex_entry_mode.py 1328 2007-01-19 18:16:32Z joachim $ """ reindex students_catalog entry_mode index """ request = context.REQUEST session = request.SESSION response = request.RESPONSE students = context.portal_url.getPortalObject().campus.students def rwrite(s): response.setHeader('Content-type','text/html; charset=ISO-8859-15') #response.setHeader('Content-length','%d' % (len(s))) #response.setStatus('OK') response.write(s) cat = context.students_catalog ems = cat.uniqueValuesFor('entry_mode') rwrite("entry_mode values: %s
\n" % (str(ems))) for em in ems: res = cat(entry_mode = em) rwrite("entry_mode: %s = %d
\n" % (em,len(res))) #from Products.zdb import set_trace;set_trace() sbrains = cat() count = 0 lc = 1 rwrite("%3d " % lc) for sb in sbrains: normalized = False em = context.getFromData_entry_mode(sb.id) ec = 'x' if em is None: ec = 'n' em = 'None' if em in ('UME','DE'): ec = 'C' normalized = True elif sb.entry_mode in ('DIRECT', 'DIRECT ENTRY',): ec = 'D' em = 'DE' normalized = True elif sb.entry_mode in ('U.M.E', 'UNE',): ec = 'U' em ="UME" normalized = True elif not sb.entry_mode: ec = 'u' em ="UME" normalized = True if ec != "C" and em != sb.entry_mode: #from Products.zdb import set_trace;set_trace() app = getattr(getattr(students,sb.id),'application',None) ec = 'a' if app is not None: ec = 'A' app.getContent().edit(mapping={'entry_mode': sb.entry_mode}) if normalized: cat.modifyRecord(id = sb.id, entry_mode = em) rwrite(ec) count += 1 if count > 60: lc += 1 rwrite("
\n%3d " % lc) count = 0