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 | """ |
---|
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_306_resolve') |
---|
20 | from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob |
---|
21 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
22 | pins = context.portal_pins() |
---|
23 | scat = context.students_catalog |
---|
24 | |
---|
25 | request = context.REQUEST |
---|
26 | session = request.SESSION |
---|
27 | response = request.RESPONSE |
---|
28 | setheader = request.RESPONSE.setHeader |
---|
29 | students = 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 | |
---|
36 | count = 0 |
---|
37 | commit_after = 100 |
---|
38 | todelete = [] |
---|
39 | |
---|
40 | total = len(pins) |
---|
41 | logger.info('started, %d PINs found' % total) |
---|
42 | |
---|
43 | for 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) |
---|
70 | logger.info('finished for %d of %d' % (count,total)) |
---|
71 | return |
---|
72 | |
---|
73 | |
---|