source: WAeUP_SRP/trunk/skins/waeup_utilities/changeCostInPins.py @ 13041

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

improve logging

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1## Script (Python) "changeCostInPins"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=batch_id,old_cost
8##title=
9##
10# $Id: changeCostInPins.py 3132 2008-02-08 21:10:38Z 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
24import logging
25import DateTime
26logger = logging.getLogger('Skins.changeCostInPins')
27from Products.AdvancedQuery import Eq, Between, Le,In
28aq_pins = context.portal_pins.evalAdvancedQuery
29
30request = context.REQUEST
31session = request.SESSION
32batch = getattr(context.portal_url.getPortalObject().campus.pins,batch_id,None)
33if batch is None:
34    logger.info('No such batch %s' % batch_id)
35new_cost = batch.getContent().cost
36prefix_batch = batch_id.replace('_','')
37query = Eq('prefix_batch',prefix_batch)
38pins = aq_pins(query)
39if len(pins) is None:
40    logger.info('No pins with prefix_batch  %s' % prefix_batch)
41edited = 0
42wrong = 0
43count = 0
44commit_after = 50
45#logger.info('started to change %d pins cost from %s to %s' %
46#            (len(pins),old_cost,new_cost))
47to_edit = []
48for pin in pins:
49    count += 1
50    if pin.cost != float(old_cost):
51        logger.info("%s: cost %s does not match %s" % (pin.key,
52                                                       pin.cost,
53                                                       old_cost))
54        wrong += 1
55        continue
56    to_edit += pin.pin,
57logger.info('%d %s pins found, start editing cost from %s to %s' %
58            (len(pins),batch_id,old_cost,new_cost))           
59for pin in to_edit:
60    context.portal_pins.modifyRecord(**{'pin': pin, 'cost': float(new_cost)})
61logger.info('finished editing %d %s pins, %d had wrong cost' % (count, batch_id,
62                                                                     wrong))
Note: See TracBrowser for help on using the repository browser.