source: WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part1.py @ 3072

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

change logging message

File size: 3.2 KB
Line 
1## Script (Python) "ti_441_resolve_part1"
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_441_resolve.py 2979 2008-01-05 15:01:33Z 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
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.ti_441_resolve_part1')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_portal = context.portal_catalog_real.evalAdvancedQuery
30aq_students = context.students_catalog.evalAdvancedQuery
31students_folder = context.portal_url.getPortalObject().campus.students
32
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37def rwrite(s):
38    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
39    response.write("%s<br>\n\r" % s)
40
41re_split = context.waeup_tool.re_split
42query = Eq('lga','')
43student_records = aq_students(query)
44total = len(student_records)
45logger.info("found %d records with empty clearance lga" % total)
46count = 0
47commit_after = 100
48logger.info('started to fix %d records' % total)
49mapping = context.waeup_tool.getStatesLgas()
50states = mapping['states']
51lgas = mapping['lgas']
52words_dict = mapping['word_dict']
53d = {}
54for student_record in student_records:
55    count += 1
56    jamb_state = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_state
57    jamb_lga = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_lga
58    words = ' '.join((jamb_state, jamb_lga))
59    # words = re_split('[^a-zA-Z0-9/]',words)
60    # lga_words = []
61    # for word in words:
62    #     if word:
63    #         lga_words += word.lower(),
64    # lga_words.sort()
65    # state_lga = ''
66    # while not state_lga:
67    #     for k,l in words_dict.items():
68    #         if lga_words == l:
69    #             state_lga = k
70    #             break
71    #     break
72    state_lga = context.waeup_tool.findLga(words,words_dict)
73    if state_lga:
74        msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id)
75        #rwrite(msg)
76        logger.info(msg)
77        d[student_record.id] = state_lga
78        if len(d) and not len(d)  % commit_after:
79            logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
80    else:
81        msg = "no '%s' for %s" % (words,student_record.id)
82        #logger.info(msg)
83        #rwrite(msg)
84    # if count > 150:
85    #     break
86logger.info("found %d correct lga values" % len(d))
87edited = 1
88for student_id,lga in d.items():
89    msg = "set clearance.lga to %s for %s" % (lga,student_id)
90    getattr(getattr(students_folder,student_id),'clearance').getContent().edit(mapping={'lga':lga})
91    logger.info(msg)
92    edited += 1
93    if edited and not edited  % commit_after:
94        context.waeup_tool.doCommit()
95        logger.info("Committing %d,  %d" % (commit_after,edited))
96logger.info('finished, %d checked, %d edited' % (count,
97                                               edited,))
98
Note: See TracBrowser for help on using the repository browser.