[2059] | 1 | ## Script (Python) "ti_167_resolve" |
---|
| 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: ti_167_resolve.py 2062 2007-07-26 20:58:59Z joachim $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
| 18 | import logging |
---|
| 19 | logger = logging.getLogger('Skins.ti_167_resolve') |
---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob |
---|
| 21 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
| 22 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 23 | |
---|
| 24 | request = context.REQUEST |
---|
| 25 | session = request.SESSION |
---|
| 26 | response = request.RESPONSE |
---|
| 27 | setheader = request.RESPONSE.setHeader |
---|
| 28 | students = context.portal_url.getPortalObject().campus.students |
---|
| 29 | |
---|
| 30 | #from string import Template |
---|
| 31 | def rwrite(s): |
---|
| 32 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 33 | response.write("%s<br>\n\r" % s) |
---|
| 34 | |
---|
| 35 | batches = context.portal_catalog(portal_type = "ScratchCardBatch") |
---|
| 36 | logger.info("starting to insert cost property into pins-catatlog") |
---|
| 37 | batch_cost = {} |
---|
| 38 | for batch in batches: |
---|
| 39 | prefix_batch = ''.join(batch.getId.split('_')) |
---|
| 40 | cost = batch.getObject().getContent().cost |
---|
| 41 | batch_cost[prefix_batch] = cost |
---|
[2060] | 42 | query = Eq('prefix_batch',prefix_batch) |
---|
| 43 | pins = aq_pins(query) |
---|
| 44 | for pin in pins: |
---|
| 45 | context.portal_pins.modifyRecord(pin=pin.pin,cost=cost) |
---|
| 46 | #rwrite("%s, %s" % (prefix_batch,cost)) |
---|
| 47 | logger.info("Cost %s (for %s) in portal_pins replaced" % (cost,prefix_batch)) |
---|
[2059] | 48 | query = Eq('portal_type',"Payment") |
---|
| 49 | payments = aq_portal(query) |
---|
| 50 | count = 0 |
---|
| 51 | no_cost = 0 |
---|
[2062] | 52 | commit_after = 100 |
---|
[2059] | 53 | for payment in payments: |
---|
| 54 | if payment.Title.find('n/a') > -1: |
---|
| 55 | #set_trace() |
---|
| 56 | payment_doc = payment.getObject().getContent() |
---|
| 57 | prefix_batch = ''.join(str(payment_doc.order_id).split('-')[:2]) |
---|
| 58 | if batch_cost.has_key(prefix_batch): |
---|
| 59 | count += 1 |
---|
[2060] | 60 | payment_doc.edit(mapping = {'amount': |
---|
[2059] | 61 | batch_cost[prefix_batch]}) |
---|
[2060] | 62 | #rwrite("%s: %s:%s" % (count,prefix_batch,payment_doc.order_id)) |
---|
| 63 | logger.info("Cost in payment object %s (%s) replaced (#%s)" % (payment.id,payment_doc.order_id,count)) |
---|
[2059] | 64 | else: |
---|
[2060] | 65 | #rwrite("cost %s:%s not found" % (prefix_batch,payment_doc.order_id)) |
---|
| 66 | logger.info("Prefix %s (%s) not found" % (prefix_batch,payment_doc.order_id)) |
---|
[2059] | 67 | no_cost +=1 |
---|
[2062] | 68 | if count and not count % commit_after: |
---|
[2061] | 69 | context.waeup_tool.doCommit() |
---|
[2062] | 70 | logger.info("Committing %s transactions, total %s" % (commit_after,count)) |
---|
[2059] | 71 | logger.info("updated %d payment amounts, %d costs not found" % (count,no_cost)) |
---|
| 72 | |
---|
[2060] | 73 | |
---|