source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_306_resolve.py @ 16153

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

tool for ticket #303

File size: 2.2 KB
Line 
1## Script (Python) "ti_306_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_306_resolve.py 1983 2007-07-04 07:32:36Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18import logging
19logger = logging.getLogger('Skins.ti_306_resolve')
20from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob
21aq_pins = context.portal_pins.evalAdvancedQuery
22pins = context.portal_pins()
23scat = context.students_catalog
24
25request = context.REQUEST
26session = request.SESSION
27response = request.RESPONSE
28setheader = request.RESPONSE.setHeader
29students = context.portal_url.getPortalObject().campus.students
30
31#query = Eq('pin','APP')
32#brains = aq_pins(query)
33#total = len(brains)
34#logger.info('found %d APP PINs' % total)
35
36count = 0
37commit_after = 100
38todelete = []
39
40total = len(pins)
41logger.info('started, %d PINs found' % total)
42
43for brain in pins:
44    if not brain.pin.startswith('APP') or not brain.student:
45        continue
46
47    application = None
48    sbrains = scat(jamb_reg_no = brain.student.upper())
49    if len(sbrains)>0:
50        sbrain = sbrains[0]
51    else:
52        logger.info('%s %s' % (brain.pin,brain.student))
53        continue
54    try:
55        application = getattr(getattr(students,sbrain.id),'application')
56    except:
57        logger.info('%s, application does not exist' % (brain.student))
58        continue
59    prefix,batch_no,number = brain.pin[:3],brain.pin[3:-10],brain.pin[-10:]
60    app_doc = application.getContent()
61    if app_doc.app_ac_pin.startswith('APP'):
62        logger.info('%s, %s, %s already shows correct PIN %s (reason: check_admission failed the first time)' % (count, brain.student,sbrain.id,app_doc.app_ac_pin))
63        continue
64    app_doc.edit(mapping={'app_ac_pin' : '%s-%s-%s' % (prefix,batch_no,number)})
65    logger.info('%s, %s, %s, %s-%s-%s replaced' % (count, brain.student,sbrain.id,prefix,batch_no,number))
66    count += 1
67    if count and not count % commit_after:
68        context.waeup_tool.doCommit()
69        logger.info("committed %d transactions" % commit_after)
70logger.info('finished for %d of %d' % (count,total))
71return
72
73
Note: See TracBrowser for help on using the repository browser.