Changeset 6276 for main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py
- Timestamp:
- 4 Jun 2011, 11:17:28 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py
r6273 r6276 15 15 from zope.schema import getFields 16 16 from waeup.sirp.interfaces import ( 17 IBatchProcessor, ISchemaTypeConverter, FatalCSVError, DuplicationError, 18 IObjectConverter) 17 IBatchProcessor, FatalCSVError, DuplicationError, IObjectConverter) 19 18 20 19 class BatchProcessor(grok.GlobalUtility): … … 122 121 result[raw_header[num]] = field 123 122 return result 124 125 def getFieldConverters(self, fieldnames):126 """Get converters for fieldnames.127 """128 result = dict()129 for key, field in getFields(self.iface).items():130 if key not in fieldnames:131 continue132 converter = ISchemaTypeConverter(field)133 result[key] = converter134 return result135 136 def convertToTypes(self, row, converter_dict):137 """Convert values in given row to destination type.138 """139 if '--IGNORE--' in row.keys():140 del row['--IGNORE--']141 warnings = []142 for key, value in row.items():143 converter = converter_dict.get(key, None)144 if converter:145 try:146 row.update({key:converter_dict[key].fromString(value)})147 except:148 msg = "conversion error: field %s: %s %r" % (149 key, sys.exc_info()[0], sys.exc_info()[1])150 warnings.append(msg)151 return (row, warnings)152 123 153 124 def stringFromErrs(self, errors, inv_errors): … … 244 215 self.checkHeaders(headerfields, mode) 245 216 mapping = self.getMapping(path, headerfields, mode) 246 converters = self.getFieldConverters(headerfields)247 217 reader = csv.DictReader(open(path, 'rb')) 248 218
Note: See TracChangeset for help on using the changeset viewer.