source: WAeUP_SRP/trunk/skins/waeup_utilities/copyLGA.py @ 3902

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

transform resolve script into a regular utility script

This script must always be called after importing students in create mode.

File size: 2.6 KB
Line 
1## Script (Python) "copyLGA"
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
27#logger = logging.getLogger('Skins.ti_441_resolve_part1')
28logger = logging.getLogger('Skins.copyLGA')
29from Products.AdvancedQuery import Eq, Between, Le,In
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31aq_students = context.students_catalog.evalAdvancedQuery
32students_folder = context.portal_url.getPortalObject().campus.students
33
34request = context.REQUEST
35session = request.SESSION
36response = request.RESPONSE
37setheader = request.RESPONSE.setHeader
38
39re_split = context.waeup_tool.re_split
40query = Eq('lga','')
41student_records = aq_students(query)
42total = len(student_records)
43logger.info("found %d records with empty clearance lga" % total)
44count = 0
45commit_after = 100
46logger.info('started to fix %d records' % total)
47mapping = context.waeup_tool.getStatesLgas()
48states = mapping['states']
49lgas = mapping['lgas']
50words_dict = mapping['word_dict']
51d = {}
52for student_record in student_records:
53    count += 1
54    jamb_state = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_state
55    jamb_lga = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_lga
56    words = ' '.join((jamb_state, jamb_lga))
57    state_lga = context.waeup_tool.findLga(words,words_dict)
58    if state_lga:
59        msg = "found %s for %s " % (state_lga,student_record.id)
60        logger.info(msg)
61        d[student_record.id] = state_lga
62        if len(d) and not len(d)  % commit_after:
63            logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
64    else:
65        msg = "no '%s' for %s" % (words,student_record.id)
66logger.info("found %d correct lga values" % len(d))
67edited = 1
68for student_id,lga in d.items():
69    msg = "set clearance.lga to %s for %s" % (lga,student_id)
70    getattr(getattr(students_folder,student_id),'clearance').getContent().edit(mapping={'lga':lga})
71    logger.info(msg)
72    edited += 1
73    if edited and not edited  % commit_after:
74        context.waeup_tool.doCommit()
75        logger.info("Committing %d,  %d" % (commit_after,edited))
76logger.info('finished, %d checked, %d edited' % (count,
77                                               edited,))
78
Note: See TracBrowser for help on using the repository browser.