1 | ## Script (Python) "upgradePayments.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: upgradePayments.py 2918 2007-12-10 23:57:23Z 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','joachim'): |
---|
22 | return |
---|
23 | |
---|
24 | |
---|
25 | import logging |
---|
26 | import DateTime |
---|
27 | logger = logging.getLogger('Skins.upgradePayments') |
---|
28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
30 | aq_student = context.students_catalog.evalAdvancedQuery |
---|
31 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
32 | |
---|
33 | request = context.REQUEST |
---|
34 | session = request.SESSION |
---|
35 | response = request.RESPONSE |
---|
36 | setheader = 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 | |
---|
41 | count = 1 |
---|
42 | d = {} |
---|
43 | l = [] |
---|
44 | sum_total = 0.0 |
---|
45 | log_after = 100 |
---|
46 | logger.info("start") |
---|
47 | query = Eq('portal_type','Payment') |
---|
48 | payments = aq_portal(query,sortSpecs=('container_path',)) |
---|
49 | total = len(payments) |
---|
50 | logger.info("found %d payments" % total) |
---|
51 | sid = "xxx" |
---|
52 | count = 0 |
---|
53 | commit_after = 5 |
---|
54 | #commit_count = 0 |
---|
55 | |
---|
56 | student_id = '' |
---|
57 | for payment_brain in payments: |
---|
58 | count += 1 |
---|
59 | payment = payment_brain.getObject() |
---|
60 | if payment_brain.getPath().split('/')[-3] != student_id: |
---|
61 | student_id = payment_brain.getPath().split('/')[-3] |
---|
62 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
63 | payment['updatePayment'](student_record) |
---|
64 | logger.info('upgraded student %s payment %s' % (student_record.id,payment.getId())) |
---|
65 | #if not count % commit_after: |
---|
66 | # logger.info("committing %d total %d" % (commit_after,count)) |
---|
67 | #commit_count += 1 |
---|
68 | #if not commit_count % 2: |
---|
69 | # break |
---|
70 | logger.info("%d of %d upgraded" % (count,total)) |
---|