[5609] | 1 | ## Script (Python) "purgeDefinedPayments"
|
---|
| 2 | ##bind container=container
|
---|
| 3 | ##bind context=context
|
---|
| 4 | ##bind namespace=
|
---|
| 5 | ##bind script=script
|
---|
| 6 | ##bind subpath=traverse_subpath
|
---|
| 7 | ##parameters=resp_desc=None
|
---|
| 8 | ##title=
|
---|
| 9 | ##
|
---|
| 10 | # $Id: purgeDefinedPayments.py 5610 2010-12-10 09:28:18Z henrik $
|
---|
| 11 | """
|
---|
| 12 | """
|
---|
| 13 | try:
|
---|
| 14 | from Products.zdb import set_trace
|
---|
| 15 | except:
|
---|
| 16 | def set_trace():
|
---|
| 17 | pass
|
---|
| 18 |
|
---|
| 19 | mtool = context.portal_membership
|
---|
| 20 | member = mtool.getAuthenticatedMember()
|
---|
| 21 | if str(member) not in ('admin'):
|
---|
| 22 | return
|
---|
| 23 | students_folder = context.portal_url.getPortalObject().campus.students
|
---|
| 24 |
|
---|
| 25 | import logging
|
---|
| 26 | import DateTime
|
---|
| 27 | logger = logging.getLogger('Skins.purgeDefinedPayments')
|
---|
[5610] | 28 | from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob,MatchRegexp
|
---|
[5609] | 29 | aq_payments = context.payments_catalog.evalAdvancedQuery
|
---|
| 30 |
|
---|
| 31 | commit_after = 100
|
---|
| 32 | counter = 0
|
---|
[5610] | 33 | counter_all = 0
|
---|
[5609] | 34 |
|
---|
[5610] | 35 | payments = context.payments_catalog(status = 'failed')
|
---|
| 36 | #query = In('resp_desc','Invalid*',)
|
---|
| 37 | #payments = aq_payments(query)
|
---|
[5609] | 38 |
|
---|
[5610] | 39 | logger.info("started, %d failed payments found" % len(payments))
|
---|
| 40 |
|
---|
[5609] | 41 | for payment in payments:
|
---|
[5610] | 42 | counter_all += 1
|
---|
| 43 | if not 'Cumulative total of payment' in payment.resp_desc:
|
---|
| 44 | continue
|
---|
[5609] | 45 | payments_folder = getattr(getattr(students_folder,payment.student_id),'payments',None)
|
---|
| 46 | counter += 1
|
---|
| 47 | pid = 'p' + payment.order_id[6:]
|
---|
| 48 | if getattr(payments_folder,pid,False):
|
---|
[5610] | 49 | logger.info('object deleted: %s , %s, %s, %d of %d' % (payment.student_id, pid, payment.resp_desc, counter, counter_all))
|
---|
[5609] | 50 | else:
|
---|
| 51 | logger.info('no object: %s, %s' % (payment.student_id, pid))
|
---|
| 52 | payments_folder.manage_delObjects(pid)
|
---|
| 53 |
|
---|
| 54 | if not counter % commit_after:
|
---|
| 55 | context.waeup_tool.doCommit()
|
---|
| 56 | logger.info("committing %d of total %d" % (commit_after,counter))
|
---|
| 57 |
|
---|
| 58 | context.waeup_tool.doCommit()
|
---|
| 59 | logger.info("%d committed" % (counter))
|
---|
| 60 |
|
---|
| 61 | logger.info("finished, %d payment objects removed" % (counter))
|
---|
| 62 | return 'finished!'
|
---|
| 63 |
|
---|
| 64 |
|
---|