Changeset 3009
- Timestamp:
- 11 Jan 2008, 08:54:44 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part1.py
r2980 r3009 39 39 response.write("%s<br>\n\r" % s) 40 40 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('') 41 re_split = context.waeup_tool.re_split 64 42 query = Eq('lga','') 65 43 student_records = aq_students(query) … … 69 47 commit_after = 100 70 48 logger.info('started to fix %d records' % total) 71 d,states,lgas = getLGAs() 49 mapping = context.waeup_tool.getStatesLgas() 50 states = mapping['states'] 51 lgas = mapping['lgas'] 52 words_dict = mapping['word_dict'] 72 53 d = {} 73 54 for student_record in student_records: 74 55 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))77 56 jamb_state = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_state 78 57 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) 88 83 # if count > 150: 89 84 # break … … 91 86 edited = 1 92 87 for 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) 94 89 getattr(getattr(students_folder,student_id),'clearance').getContent().edit(mapping={'lga':lga}) 95 90 logger.info(msg)
Note: See TracChangeset for help on using the changeset viewer.