source: WAeUP_SRP/base/skins/waeup_epayment/purgePayments.py @ 2925

Last change on this file since 2925 was 2911, checked in by joachim, 17 years ago

beautify purgePayments make delete_event work for payments_catalog

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1## Script (Python) "purgePayments.py"
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: purgePayments.py 2911 2007-12-10 16:24:55Z joachim $
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','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.purgePayments')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_portal = context.portal_catalog_real.evalAdvancedQuery
30aq_student = context.students_catalog.evalAdvancedQuery
31students_folder = context.portal_url.getPortalObject().campus.students
32
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37#def rwrite(s):
38#    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
39#    response.write("%s<br>\n\r" % s)
40
41count = 1
42d = {}
43l = []
44sum_total = 0.0
45log_after = 100
46logger.info("start")
47query = Eq('portal_type','Payment') & Eq('review_state','opened')
48payments = aq_portal(query,sortSpecs=('container_path',))
49total = len(payments)
50logger.info("found %d payments" % total)
51#return
52sid = "xxx"
53to_del = []
54delete_count = 0
55delete_count_student = 1
56keep_count = 0
57payments_folder = None
58count = 0
59commit_after = 50
60for payment in payments:
61    p_sid = payment.getPath().split('/')[-3]
62    if sid != p_sid:
63        if count and to_del:
64            if not delete_count_student % commit_after:
65                context.waeup_tool.doCommit()
66                logger.info("committing %d total %d" % (commit_after,delete_count_student))
67            msg = "(%d/%d) found %d payments to remove, %d to keep for %s" % (count,
68                                                                              delete_count_student % commit_after,
69                                                                              len(to_del),
70                                                                              student_keep_count,
71                                                                              sid)
72            #rwrite( msg)
73            delete_count_student += 1
74            logger.info(msg)
75            payments_folder = getattr(getattr(students_folder,sid),'payments',None)
76            msg = "deleted %s of %s" % (' '.join(to_del),sid)
77            payments_folder.manage_delObjects(to_del)
78            logger.info(msg)
79        elif count and not to_del:
80            msg = "%d: found %d payments to keep for %s in review_state %s" % (count,
81                                                                  student_keep_count,
82                                                                  sid,
83                                                                  review_state,)
84            #rwrite( msg)
85        sid = p_sid
86        count += 1
87        to_del = []
88        not_del_count = 0
89        student_keep_count = 0
90        res = aq_student(Eq('id',sid))
91        if not res:# or payments_folder is None:
92            logger.info("student_id %s not found" % pin.student)
93            continue
94        student = res[0]
95        review_state = student.review_state
96    if review_state in ("school_fee_paid",
97                        "courses_registered",
98                        "courses_validated",
99                       ):
100        delete_count += 1
101        to_del += payment.getId,
102        # if payment.review_state == "opened":
103        #     #rwrite("%s : %s" % (sid,payment.Title))
104        #     delete_count += 1
105        #     to_del += payment.getId,
106        # else:
107        #     keep_count += 1
108        #     student_keep_count += 1
109    else:
110        keep_count += 1
111        student_keep_count += 1
112
113logger.info("%d of %d to purge %d to keep" % (delete_count,total,keep_count))
Note: See TracBrowser for help on using the repository browser.