source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_513_resolve.py

Last change on this file was 3371, checked in by joachim, 16 years ago

change jamb_reg_no fix for #513

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1## Script (Python) "ti_513_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_513_resolve.py 3371 2008-03-25 17:50:05Z joachim $
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
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.ti_513_resolve')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_students = context.students_catalog.evalAdvancedQuery
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31students_folder = context.portal_url.getPortalObject().campus.students
32
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37count = 0
38found = 0
39commit_after = 100
40logger.info('start')
41students = context.students_catalog()
42wrong = {}
43missing_courses = []
44wrong_starts = []
45for student in students:
46    count += 1
47    if student.jamb_reg_no.endswith('/07'):
48        pos = 0
49        if student.jamb_reg_no[:5].isalpha():
50            pos = 5
51        elif student.jamb_reg_no[:4].isalpha():
52            if student.jamb_reg_no[:4] != 'UBNO':
53                pos = 4
54        if pos:
55            d = {}
56            d['student_id'] = student.id
57            d['jamb_reg_no_old'] = student.jamb_reg_no
58            d['jamb_reg_no'] = student.jamb_reg_no[:3]+student.jamb_reg_no[pos:]
59            #set_trace()
60            if student.jamb_reg_no[:pos] not in wrong_starts:
61                wrong_starts += student.jamb_reg_no[:pos],
62            wrong[student.id] = d
63logger.info('found %d wrong of %d' % (len(wrong),count))
64count = 0
65for student_id,d in wrong.items():
66    try:
67        getattr(getattr(students_folder,student_id),'application').getContent().edit(mapping=d)
68        logger.info("%(student_id)s changed jamb_reg_no from %(jamb_reg_no_old)s to %(jamb_reg_no)s" % d)
69    except:
70        logger.info("%(student_id)s change failed")
71    if count and not count % commit_after:
72        context.waeup_tool.doCommit()
73        logger.info("committing %d of total %d" % (commit_after,count))
74    count += 1
75logger.info('finished')                   
Note: See TracBrowser for help on using the repository browser.