source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_167_resolve.py @ 8794

Last change on this file since 8794 was 2062, checked in by joachim, 17 years ago

fix commit

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
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"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18import logging
19logger = logging.getLogger('Skins.ti_167_resolve')
20from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob
21aq_pins = context.portal_pins.evalAdvancedQuery
22aq_portal = context.portal_catalog_real.evalAdvancedQuery
23
24request = context.REQUEST
25session = request.SESSION
26response = request.RESPONSE
27setheader = request.RESPONSE.setHeader
28students = context.portal_url.getPortalObject().campus.students
29
30#from string import Template
31def rwrite(s):
32    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
33    response.write("%s<br>\n\r" % s)
34
35batches = context.portal_catalog(portal_type = "ScratchCardBatch")
36logger.info("starting to insert cost property into pins-catatlog")
37batch_cost = {}
38for batch in batches:
39    prefix_batch = ''.join(batch.getId.split('_'))
40    cost = batch.getObject().getContent().cost
41    batch_cost[prefix_batch] = cost
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))
48query = Eq('portal_type',"Payment")
49payments = aq_portal(query)
50count = 0
51no_cost = 0
52commit_after = 100
53for 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
60            payment_doc.edit(mapping = {'amount':
61                                        batch_cost[prefix_batch]})
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))
64        else:
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))
67            no_cost +=1
68    if count and not count % commit_after:
69        context.waeup_tool.doCommit()
70        logger.info("Committing %s transactions, total %s" % (commit_after,count))
71logger.info("updated %d payment amounts, %d costs not found" % (count,no_cost))
72
73
Note: See TracBrowser for help on using the repository browser.