- Timestamp:
- 11 Mar 2008, 14:16:31 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/Upload.py
r3314 r3316 14 14 from WAeUPImport import CourseImport,CourseResultImport 15 15 from WAeUPImport import DepartmentImport,FacultyImport,StudentImport,VerdictImport 16 from WAeUPImport import NO_KEY 16 from WAeUPImport import NO_KEY,IGNORE 17 17 18 18 import logging … … 55 55 security = ClassSecurityInfo() 56 56 NO_KEY = NO_KEY 57 IGNORE = IGNORE 57 58 security.declareProtected(View,"Title") ###( 58 59 def Title(self): … … 89 90 if invalid_keys: 90 91 msg += "invalid keys in heading" 91 keys = importer.getHeadlineFields(headline,values) 92 err,keys = importer.getHeadlineFields(headline,values) 93 if err: 94 msg += err 92 95 return msg,keys 93 96 ###) … … 120 123 records = [record for record in reader] 121 124 #import pdb;pdb.set_trace() 122 for old,new in key_pairs: 123 pos = headline.index(old) 125 for old,new,pos in key_pairs: 124 126 del headline[pos] 125 127 headline.insert(pos,new) -
WAeUP_SRP/base/WAeUPImport.py
r3315 r3316 52 52 53 53 NO_KEY = '----' 54 54 IGNORE = 'ignore' 55 55 class WAeUPImport(UniqueObject, SimpleItem, ActionProviderBase): ###( 56 56 """ WAeUPImport """ … … 143 143 import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore') 144 144 or k.strip() in self.info.keys())] 145 # import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())] 145 146 diff2schema = set(import_keys).difference(set(self.schema.keys())) 146 147 diff2layout = set(import_keys).difference(set(self.layout.keys())) … … 153 154 def getHeadlineFields(self,headline,values): ###( 154 155 """ check the headline of a csv file """ 155 # import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore')156 # or k.strip() in self.info.keys())]157 import_keys = [k.strip() for k in headline ]156 # import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore') 157 # or k.strip() in self.info.keys())] 158 import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())] 158 159 si = set(import_keys) 159 160 ss = set(self.schema.keys()) 160 161 161 162 invalid_keys = si - ss 162 #diff2layout = set(import_keys).difference(set(self.layout.keys()))163 163 keys = [] 164 164 i = 0 165 for k in import_keys: 166 if k in invalid_keys: 167 keys += (k,NO_KEY,values[i]), 168 else: 169 keys += (k,k,values[i]), 170 i += 1 171 return keys 165 duplicates = False 166 singels = [] 167 msg = '' 168 while True: 169 if len(values) != len(import_keys): 170 msg += "%d fields in headline but %d values" % (len(import_keys),len(values)) 171 break 172 for k in import_keys: 173 if k in singels: 174 keys += (k,'DUP_%s' % k,values[i],'duplicate'), 175 msg += ("duplicate %s," % k) 176 keys[singels.index(k)] = (k,'DUP_%s' % k,values[singels.index(k)],'duplicate') 177 elif k in invalid_keys and not k.startswith(IGNORE): 178 keys += (k,NO_KEY,values[i],'invalid'), 179 else: 180 keys += (k,k,values[i],''), 181 i += 1 182 singels += k, 183 break 184 return msg,keys 172 185 ###) 173 186 ###) -
WAeUP_SRP/base/skins/waeup_upload/uploads_form.pt
r3315 r3316 66 66 <th>Value from 1. record</th> 67 67 </tr> 68 <tr tal:repeat="key row/ invalid_keys">68 <tr tal:repeat="key row/fields"> 69 69 <td colspan="1"> 70 <font tal:attributes="color python: test(key[1] == '----' and not key[0].startswith('ignore'),'red','black')" tal:content="python: key[0]" /> 70 <font tal:attributes="color python: test(key[3],'red','black')"> 71 <span tal:content="python: key[1]" tal:omit-tag=""/> 72 <span tal:condition="python: key[3]" tal:content="python: key[3]" tal:omit-tag=""/> 73 </font> 71 74 </td> 72 75 <td colspan="1" 73 76 tal:define="old_key python: key[0];new_key python: key[1];"> 74 <select tal:attributes="name string:${row/id}|${ old_key}.valid_key:record">77 <select tal:attributes="name string:${row/id}|${repeat/key/index}.valid_key:record"> 75 78 <option tal:repeat="new row/valid_keys" 76 tal:attributes="value new; selected python: new == new_key"79 tal:attributes="value new; selected python: new_key == new" 77 80 tal:content="new" /> 78 81 </select><br /> -
WAeUP_SRP/base/skins/waeup_upload/uploads_index.py
r3314 r3316 36 36 edit = request.form.has_key('edit') 37 37 ids = request.get('ids',[]) 38 #set_trace()39 38 if edit and ids: 40 39 for long_id in ids: … … 46 45 msg, invalid_keys = doc['checkKeys']() 47 46 new_keys = [] 48 for old_key,previous,value in invalid_keys: 49 id_key = "%s|%s" % (short_id,old_key) 47 i = 0 48 for old_key,previous,value,err in invalid_keys: 49 id_key = "%s|%s" % (short_id,i) 50 50 if request.form.has_key(id_key): 51 51 new_key = request.form.get(id_key)['valid_key'] 52 if new_key != old_key and new_key != doc.NO_KEY: 53 new_keys += (old_key,new_key), 52 if new_key != old_key: 53 if new_key == doc.IGNORE: 54 new_keys += (old_key,"%s_%s" % (doc.IGNORE,old_key),i), 55 elif new_key != doc.NO_KEY: 56 new_keys += (old_key,new_key,i), 57 i += 1 54 58 if new_keys: 55 59 doc.editHeadline(new_keys) 56 60 for key in new_keys: 57 logger.info('%s changed column heading in file %s from %s to %s' % (member,long_id,key[0],key[1])) 61 logger.info('%s changed column %s heading in file %s from %s to %s' % (member, 62 key[2], 63 long_id, 64 key[0], 65 key[1])) 58 66 return request.RESPONSE.redirect(context.absolute_url()) 59 67 … … 67 75 row['valid_keys'] = doc['getKeys']() 68 76 row['valid_keys'][0:0] = doc.NO_KEY, 77 row['valid_keys'][1:1] = doc.IGNORE, 69 78 row['id'] = id.replace('.csv','') 70 79 row['title'] = doc.filename 71 80 row['url'] = upload.absolute_url() 72 81 row['imported'] = False 73 row[' invalid_keys'] = []82 row['fields'] = [] 74 83 import_message = getattr(doc,'import_message','') 75 84 if import_message: … … 83 92 add_to = imported 84 93 else: 85 row['msg'],row[' invalid_keys'] = doc['checkKeys']()94 row['msg'],row['fields'] = doc['checkKeys']() 86 95 if not (request.has_key('goto_edit') and id in ids) and not row['msg']: 87 96 add_to = importable
Note: See TracChangeset for help on using the changeset viewer.