## Script (Python) "fixApplicantsStatus"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: fix_applicants_status.py 2145 2007-08-22 09:48:40Z joachim $
"""
"""
try:
    from Products.zdb import set_trace
except:
    def set_trace():
        pass
import logging
logger = logging.getLogger('skins.fixApplicantsStatus')
from Products.AdvancedQuery import Eq, Between, Le,In
applicants = context.applicants_catalog
aq_applicants = applicants.evalAdvancedQuery

request = context.REQUEST
session = request.SESSION
response = request.RESPONSE
setheader = request.RESPONSE.setHeader
#from string import Template
def rwrite(s):
    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
    response.write("%s" % s)
def rwrite_ln(s):
    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
    response.write("%s<br>\n\r" % s)

#logger.info('')
brains = applicants()
total = len(brains)
logger.info('%d applicants' % total)
count = 0
to_change = []
for brain in brains:
    count += 1
    if brain.pin and not brain.status:
        to_change.append(brain.reg_no)
    if count and not count % 200:
        rwrite_ln('.')
        rwrite('%d: ' % (count / 200))
    else:
        rwrite('.')
logger.info('%d to change' % len(to_change))
data = {'status': 'entered'}
for reg_no in to_change:
    data['reg_no'] = reg_no
    applicants.modifyRecord(**data)
    rwrite_ln('%s status set to entered' % reg_no)
    logger.info('%s status set to entered' % reg_no)
logger.info('%d changed' % len(to_change))


