source: WAeUP_SRP/trunk/skins/waeup_epayment/purgeSFPayments.py @ 4398

Last change on this file since 4398 was 3967, checked in by Henrik Bettermann, 16 years ago

session, level, and mode widgets must not allow empty strings
So far, the mode vocabulary has only been changed for FUT Minna. Should be changed for other portals too.

File size: 2.5 KB
RevLine 
[3965]1## Script (Python) "purgeSFPayments"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: purgeSFPayments.py 3132 2008-02-08 21:10:38Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin'):
22    return
23students_folder = context.portal_url.getPortalObject().campus.students   
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.purgeSFPayments')
28from Products.AdvancedQuery import Eq, Between, Le,In
29
30paid_status = ('school_fee_paid','courses_registered','courses_validated')
31students = context.students_catalog(review_state = paid_status)
[3967]32student_total = len(students)
[3965]33counter = 0
34counter_unpaid = 0
35commit_after = 100
36records_to_del = []
[3967]37student_count = 0
[3965]38for student in students:
[3967]39    student_count += 1
[3965]40    to_del = []
41    student_id = student.id
42    payments_folder = getattr(getattr(students_folder,student_id),'payments',None)       
43    payments = context.payments_catalog(student_id = student_id)
44    for payment in payments:
45        if payment.status != 'paid':
46            counter_unpaid += 1
47        if payment.status != 'started' or payment.category != 'schoolfee':
48            continue
49        counter += 1
50        pid = 'p' + payment.order_id[6:]   
51        #logger.info('to be removed: %s, %s, %s, %s, %s' % (payment.student_id, sbrain.review_state, payment.order_id, payment.status, payment.category))
52        if getattr(payments_folder,pid,False):
53            to_del += pid,
[3967]54            logger.info('object deleted: %s (%d of %d), %s' % (payment.student_id, student_count, student_total, pid))
[3965]55        else:
56            logger.info('no object: %s, %s' % (payment.student_id, pid))
57            records_to_del.append(payment.order_id)
58            #context.payments_catalog.deleteRecord(payment.order_id)
59        if not counter % commit_after:
60            context.waeup_tool.doCommit()
61            logger.info("committing %d of total %d" % (commit_after,counter))
62        #if counter > 30:
63        #    return
64    payments_folder.manage_delObjects(to_del)
65context.waeup_tool.doCommit()
66logger.info("%d committed" % (counter))   
67
68for uid in records_to_del:
69    context.payments_catalog.deleteRecord(uid)       
70    logger.info("%s deleted" % (uid))   
71
72logger.info("finished, %d of %d unpaid payment objects removed" % (counter, counter_unpaid))
73return 'finished!'
74
75
Note: See TracBrowser for help on using the repository browser.