Changeset 8220 for main/waeup.kofa/trunk/src/waeup/kofa
- Timestamp:
- 19 Apr 2012, 14:19:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r8214 r8220 39 39 This is a non-active baseclass. 40 40 """ 41 grok. provides(IBatchProcessor)41 grok.implements(IBatchProcessor) 42 42 grok.context(Interface) 43 43 grok.baseclass() … … 200 200 def updateEntry(self, obj, row, site): 201 201 """Update obj to the values given in row. 202 """ 202 203 Returns a string describing the fields changed. 204 """ 205 changed = [] 203 206 for key, value in row.items(): 207 # Skip fields to be ignored. 208 if value == IGNORE_MARKER: 209 continue 204 210 # Skip fields not declared in interface. 205 if hasattr(obj, key): 206 # Set attribute to None if value is marked for deletion 207 if value != '<IGNORE>': 208 setattr(obj, key, value) 209 #if value == DELETIONMARKER: 210 # setattr(obj, key, None) 211 #elif value is not None: 212 # setattr(obj, key, value) 213 return 211 if not hasattr(obj, key): 212 continue 213 setattr(obj, key, value) 214 changed.append('%s=%s' % (key, value)) 215 return ', '.join(changed) 214 216 215 217 def createLogfile(self, path, fail_path, num, warnings, mode, user, … … 250 252 return 251 253 252 def checkConversion(self, row, mode='ignore' ):254 def checkConversion(self, row, mode='ignore', ignore_empty=True): 253 255 """Validates all values in row. 254 256 """ 255 257 converter = IObjectConverter(self.iface) 256 258 errs, inv_errs, conv_dict = converter.fromStringDict( 257 row, self.factory_name )259 row, self.factory_name, mode=mode) 258 260 return errs, inv_errs, conv_dict 259 261 260 262 def doImport(self, path, headerfields, mode='create', user='Unknown', 261 logger=None ):263 logger=None, ignore_empty=True): 262 264 """Perform actual import. 263 265 """ … … 292 294 string_row = self.applyMapping(raw_row, mapping) 293 295 row = dict(string_row.items()) # create deep copy 296 if ignore_empty and mode in ('update'): 297 # replace empty strings with ignore-markers 298 for key, val in row.items(): 299 if val == '': 300 row.update(key=IGNORE_MARKER) 294 301 errs, inv_errs, conv_dict = self.checkConversion(string_row, mode) 295 302 if errs or inv_errs: … … 312 319 self.writeFailedRow( 313 320 failed_writer, string_row, 314 "This object already exists in the same container. Skipping.") 321 "This object already exists in the same container. " 322 "Skipping.") 315 323 continue 316 324 obj = self.callFactory()
Note: See TracChangeset for help on using the changeset viewer.