## Script (Python) "purgePayments2" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: purgePayments2.py 3132 2008-02-08 21:10:38Z 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'): return students_folder = context.portal_url.getPortalObject().campus.students import logging import DateTime logger = logging.getLogger('Skins.purgePayments2') from Products.AdvancedQuery import Eq, Between, Le,In paid_status = ('school_fee_paid','courses_registered','courses_validated') students = context.students_catalog(review_state = paid_status) counter = 0 counter_unpaid = 0 commit_after = 100 for student in students: to_del = [] student_id = student.id payments_folder = getattr(getattr(students_folder,student_id),'payments',None) payments = context.payments_catalog(student_id = student_id) for payment in payments: if payment.status != 'paid': counter_unpaid += 1 if payment.status != 'started' or payment.category != 'schoolfee': continue counter += 1 pid = 'p' + payment.order_id[6:] #logger.info('to be removed: %s, %s, %s, %s, %s' % (payment.student_id, sbrain.review_state, payment.order_id, payment.status, payment.category)) logger.info('object deleted: %s, %s' % (payment.student_id, pid)) to_del += pid, if not counter % commit_after: context.waeup_tool.doCommit() logger.info("committing %d of total %d" % (commit_after,counter)) #if counter > 30: # return payments_folder.manage_delObjects(to_del) logger.info("finished, %d of %d unpaid payment objects removed" % (counter, counter_unpaid)) return 'finished!'