Changeset 3014
- Timestamp:
- 11 Jan 2008, 20:18:17 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r3003 r3014 78 78 def re_split(self,split_string,string): 79 79 return re.split(split_string,string) 80 80 ###) 81 81 82 82 security.declareProtected(View,'difference') ###( 83 83 def difference(self,l1,l2): 84 84 return set(l1).difference(set(l2)) 85 ###) 85 86 86 87 def rwrite(self,s): ###( … … 144 145 ###) 145 146 147 security.declareProtected(View,'findLga') ###( 148 def findLga(self,words,words_dict): 149 words = re.split('[^a-zA-Z0-9/]',words) 150 lga_words = [] 151 for word in words: 152 if word: 153 lga_words += word.strip().lower(), 154 lga_words.sort() 155 state_lga = '' 156 while not state_lga: 157 for k,l in words_dict.items(): 158 if lga_words == l: 159 state_lga = k 160 break 161 break 162 return state_lga 163 ###) 146 164 security.declareProtected(View,'getAccessInfo') ###( 147 165 def getAccessInfo(self,context): -
WAeUP_SRP/base/Widgets.py
r2875 r3014 580 580 581 581 def _getLGAs(self): 582 voc = getattr(self.portal_vocabularies,self.vocabulary)583 582 if getattr(self,'_v_states',None) is not None and\ 584 583 getattr(self,'_v_lgas',None) is not None and\ 585 getattr(self,'_v_d',None) is not None: 586 return (_v_d,_v_states,_v_lgas) 587 states = [] 588 lgas = [] 589 d = {} 590 for k,v in voc.items(): 591 parts = v.split(' / ') 592 if len(parts) == 1: 593 state = parts[0].lower() 594 lga = "" 595 elif len(parts) == 2: 596 state = parts[0].lower() 597 lga = "_".join(re.split('\W+',parts[1].lower())) 598 else: 599 continue 600 if state not in states: 601 states.append(state) 602 if lga not in lgas: 603 lgas.append(lga) 604 d[k] = v 605 self._v_d = d 606 self._v_state = state 607 self._v_lga = lga 608 return (d,states,lgas) 584 getattr(self,'_v_d',None) is not None and\ 585 getattr(self,'_v_word_dict',None) is not None: 586 return (self._v_d,self._v_states,self._v_lgas,self._v_word_dict) 587 mapping = self.waeup_tool.getStatesLgas() 588 self._v_d = mapping['lga_dict'] 589 self._v_states = mapping['states'] 590 self._v_lgas = mapping['lgas'] 591 self._v_word_dict = mapping['word_dict'] 592 return (self._v_d,self._v_states,self._v_lgas,self._v_word_dict) 593 609 594 610 595 def validate(self, datastructure, **kw): … … 619 604 return 0 620 605 v = v.lower() 621 combined,states,lgas = self._getLGAs()606 combined,states,lgas,word_dict = self._getLGAs() 622 607 datamodel = datastructure.getDataModel() 623 if not self.state_field and not self.lga_field: 624 if len(v) == 0 and self.is_required: 625 datastructure.setError(widget_id, "%s required" % widget_id) 608 if self.state_field and self.lga_field: 609 v = ' '.join((datastructure.get(self.state_field,""), 610 datastructure.get(self.lga_field,""))) 611 state_lga = self.waeup_tool.findLga(v,word_dict) 612 if not state_lga: 613 if self.is_required: 614 datastructure.setError(widget_id, "'%s' not a valid lga key" % v) 615 #datastructure.setError(widget_id, "%s required" % widget_id) 626 616 return 0 627 elif v not in combined.keys(): 628 datastructure.setError(widget_id, "'%s' not a valid lga key" % v) 629 return 0 630 datamodel[self.fields[0]] = v 631 else: 632 state = datastructure.get(self.state_field,"").lower() 633 lga = datastructure.get(self.lga_field,"").lower() 634 if widget_id == self.state_field: 635 if state not in states: 636 datastructure.setError(widget_id, "'%s' not a valid state" % v) 637 return 0 638 elif widget_id == self.lga_field: 639 if lga not in lgas: 640 datastructure.setError(widget_id, "'%s' not a valid lga" % v) 641 return 0 642 if len(state) == 0 or len(lga) == 0: 643 datastructure.setError(widget_id, "state AND lga must be given") 644 return 0 645 datamodel[self.fields[0]] = state + "_" + lga 617 else: 618 state_lga = v 619 datamodel[self.fields[0]] = state_lga 646 620 return 1 647 621 -
WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part1.py
r3009 r3014 57 57 jamb_lga = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_lga 58 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 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) 72 73 if state_lga: 73 74 msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id) … … 78 79 logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count)) 79 80 else: 80 msg = "no '%s' for %s" % ( lga_words,student_record.id)81 msg = "no '%s' for %s" % (words,student_record.id) 81 82 logger.info(msg) 82 83 #rwrite(msg) -
WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py
r2997 r3014 62 62 # return (d,states,lgas) 63 63 64 difference = context.waeup_tool.difference64 #difference = context.waeup_tool.difference 65 65 re_split = context.waeup_tool.re_split 66 66 #logger.info('') … … 69 69 logger.info("found %d students" % total) 70 70 count = 0 71 correctable = wrong = 1 71 72 commit_after = 100 72 73 logger.info('started to fix %d records in students_catalog' % total) … … 76 77 words_dict = mapping['word_dict'] 77 78 d = {} 79 not_found_lgas = [] 80 not_found_count = {} 81 rename_lgas = {} 82 rename_lgas['edo_orhionmwon'] = 'edo_ohionmwon' 78 83 for student_record in student_records: 79 84 # skip record without lga value … … 87 92 continue 88 93 #rwrite("%s: %s" % (student_record.id,student_record.lga)) 94 if student_record.lga in rename_lgas.keys(): 95 correctable += 1 96 d[student_record.id] = rename_lgas[student_record.lga] 97 if len(d) and not len(d) % commit_after: 98 logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count)) 99 continue 89 100 words = student_record.lga 90 101 if len(words.split(' / ')) == 2: 91 102 words = words.replace(' / ',' ') 92 words = re_split('[^a-zA-Z0-9/]',words) 93 lga_words = [] 94 for word in words: 95 if word: 96 lga_words += word.lower(), 97 lga_words.sort() 98 # state = sl[0].lower().strip() 99 # state = '_'.join(state.split()) 100 # lga = sl[1].lower().strip() 101 # if not lga or not state: 102 # logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id)) 103 # continue 104 state_lga = '' 105 while not state_lga: 106 for k,l in words_dict.items(): 107 if lga_words == l: 108 state_lga = k 109 break 110 break 103 state_lga = context.waeup_tool.findLga(words,words_dict) 111 104 if state_lga: 112 105 if state_lga != student_record.lga: 106 correctable += 1 113 107 msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id) 114 108 #rwrite(msg) … … 119 113 msg = "already corrected %s : %s for %s " % (state_lga,student_record.lga,student_record.id) 120 114 else: 121 msg = "no '%s' for %s" % (lga_words,student_record.id) 115 wrong += 1 116 msg = "no '%s' for %s" % (words,student_record.id) 117 if len(words) > 2: 118 if words not in not_found_lgas: 119 not_found_lgas += words, 120 not_found_count[words] = 1 121 else: 122 nfc = not_found_count[words] 123 nfc += 1 124 not_found_count[words] = nfc 125 #rwrite(msg) 122 126 # if count > 2000: 123 127 # break 128 not_found_lgas.sort() 129 for lga in not_found_lgas: 130 msg = "not found %s count: %d" % (lga,not_found_count[lga]) 131 logger.info(msg) 124 132 to_edit = len(d) 125 logger.info("found %d correct state/lga combinations of %d" % (to_edit,count)) 126 133 logger.info("found %d correctable state/lga combinations, not correctable %d total %d" % (correctable, 134 wrong, 135 count)) 127 136 edited = 1 128 137 for student_id,lga in d.items():
Note: See TracChangeset for help on using the changeset viewer.