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

Last change on this file since 2897 was 2884, checked in by Henrik Bettermann, 17 years ago

prepare to be run on uniben tonight

  • 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 2884 2007-12-08 15:30:09Z 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','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
58#set_trace()
59count = 0
60s_payments = {}
61commit_after = 50
62#set_trace()
63for payment in payments:
64    p_sid = payment.getPath().split('/')[-3]
65    # if not s_payments.has_key(p_sid):
66    #     s_payments[p_sid] = [payment,]
67    # else:
68    #     s_payments[p_sid] = context.waeup_tool.addtodict(s_payments,p_sid, payment)
69    if sid != p_sid:
70        if count and to_del:
71            if not delete_count_student % commit_after:
72                context.waeup_tool.doCommit()
73                logger.info("committing %d total %d" % (commit_after,delete_count_student))
74            delete_count_student += 1
75            msg = "(%d) found %d payments to remove, %d to keep for %s" % (count,
76                                                                    len(to_del),
77                                                                    student_keep_count,
78                                                                    sid)
79            #rwrite( msg)
80            payments_folder = getattr(getattr(students_folder,sid),'payments',None)
81            logger.info("deleting %s of %s %d" % (' '.join(to_del),sid,delete_count_student))
82            payments_folder.manage_delObjects(to_del)
83            logger.info(msg)
84        elif count and not to_del:
85            msg = "%d: found %d payments to keep for %s in review_state %s" % (count,
86                                                                  student_keep_count,
87                                                                  sid,
88                                                                  review_state)
89            #rwrite( msg)
90        sid = p_sid
91        count += 1
92        to_del = []
93        not_del_count = 0
94        student_keep_count = 0
95        res = aq_student(Eq('id',sid))
96        if not res:# or payments_folder is None:
97            logger.info("student_id %s not found" % pin.student)
98            continue
99        student = res[0]
100        review_state = student.review_state
101    if review_state in ("school_fee_paid",
102                        "courses_registered",
103                        "courses_validated",
104                        ):
105        if payment.review_state == "opened":
106            #rwrite("%s : %s" % (sid,payment.Title))
107            delete_count += 1
108            to_del += payment.getId,
109        else:
110            keep_count += 1
111            student_keep_count += 1
112    else:
113        keep_count += 1
114        student_keep_count += 1
115
116logger.info("%d of %d to purge %d to keep" % (delete_count,total,keep_count))
Note: See TracBrowser for help on using the repository browser.