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

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

add 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 2061 2007-07-26 20:57:08Z 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
52for payment in payments:
53    if payment.Title.find('n/a') > -1:
54        #set_trace()
55        payment_doc = payment.getObject().getContent()
56        prefix_batch = ''.join(str(payment_doc.order_id).split('-')[:2])
57        if batch_cost.has_key(prefix_batch):
58            count += 1
59            payment_doc.edit(mapping = {'amount':
60                                        batch_cost[prefix_batch]})
61            #rwrite("%s: %s:%s" % (count,prefix_batch,payment_doc.order_id))
62            logger.info("Cost in payment object %s (%s) replaced (#%s)" % (payment.id,payment_doc.order_id,count))
63        else:
64            #rwrite("cost %s:%s not found" % (prefix_batch,payment_doc.order_id))
65            logger.info("Prefix %s (%s) not found" % (prefix_batch,payment_doc.order_id))
66            no_cost +=1
67    if count and not count % 100:
68        context.waeup_tool.doCommit()
69        logger.info("Committing %s transactions, total %s" % (commit_count,count))
70logger.info("updated %d payment amounts, %d costs not found" % (count,no_cost))
71
72
Note: See TracBrowser for help on using the repository browser.