Changeset 3009 for WAeUP_SRP


Ignore:
Timestamp:
11 Jan 2008, 08:54:44 (17 years ago)
Author:
joachim
Message:

use new method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part1.py

    r2980 r3009  
    3939    response.write("%s<br>\n\r" % s)
    4040
    41 def getLGAs():
    42     voc = getattr(context.portal_vocabularies,'local_gov_areas')
    43     states = []
    44     lgas  = []
    45     d = {}
    46     for k,v in voc.items():
    47         parts = v.split(' / ')
    48         if len(parts) == 1:
    49             state = parts[0].lower()
    50             lga = ""
    51         elif len(parts) == 2:
    52             state = parts[0].lower()
    53             lga = "_".join(parts[1].lower().split())
    54         else:
    55             continue
    56         if state not in states:
    57             states.append(state)
    58         if lga not in lgas:
    59             lgas.append(lga)
    60         d[k] = v
    61     return (d,states,lgas)
    62 
    63 #logger.info('')
     41re_split = context.waeup_tool.re_split
    6442query = Eq('lga','')
    6543student_records = aq_students(query)
     
    6947commit_after = 100
    7048logger.info('started to fix %d records' % total)
    71 d,states,lgas = getLGAs()
     49mapping = context.waeup_tool.getStatesLgas()
     50states = mapping['states']
     51lgas = mapping['lgas']
     52words_dict = mapping['word_dict']
    7253d = {}
    7354for student_record in student_records:
    7455    count += 1
    75     if len(d) and not len(d)  % commit_after:
    76         logger.info("found %d correct lga values of %d so far" % (len(d),count))
    7756    jamb_state = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_state
    7857    jamb_lga = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_lga
    79     jamb_state = jamb_state.lower()
    80     jamb_lga = jamb_lga.lower()
    81     lga = jamb_state + '_' + jamb_lga
    82     if jamb_state and jamb_lga and jamb_state in states and jamb_lga in lgas:
    83         d[student_record.id] = lga
    84     #else:
    85     #    msg = "no %s for %s" % (lga,student_record.id)
    86     #    pass
    87     # rwrite(msg)
     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    if state_lga:
     73        msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id)
     74        #rwrite(msg)
     75        logger.info(msg)
     76        d[student_record.id] = state_lga
     77        if len(d) and not len(d)  % commit_after:
     78            logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
     79    else:
     80        msg = "no '%s' for %s" % (lga_words,student_record.id)
     81        logger.info(msg)
     82        #rwrite(msg)
    8883    # if count > 150:
    8984    #     break
     
    9186edited = 1
    9287for student_id,lga in d.items():
    93     msg = "set clearance.lga to %s for %s" % (lga,student.id)
     88    msg = "set clearance.lga to %s for %s" % (lga,student_id)
    9489    getattr(getattr(students_folder,student_id),'clearance').getContent().edit(mapping={'lga':lga})
    9590    logger.info(msg)
Note: See TracChangeset for help on using the changeset viewer.