Commit bff8385e authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Validate uploaded CSV file

parent 31d3acd8
......@@ -45,10 +45,8 @@ class UploadedFileValidataResource(ValidataResource):
def build_reader(self):
return BytesIO(self.content)
def __detect_format(self):
def __detect_format_from_file_extension(self):
ext = Path(self.filename).suffix
import ipdb
if ext in ('.csv', '.tsv', '.ods', '.xls', '.xlsx'):
return ext[1:]
return None
......@@ -57,6 +55,6 @@ class UploadedFileValidataResource(ValidataResource):
"""Uploaded file implementation"""
options = {
'scheme': 'stream',
# 'format': self.__detect_format()
'format': self.__detect_format_from_file_extension()
return (self.build_reader(), options)
......@@ -101,7 +101,7 @@ def extract_source_data(source: ValidataResource, preview_rows_nb=5):
# options['delimiter'] = csv_helpers.detect_dialect(source.source, format=source.format, scheme=source.scheme,
# custom_loaders=custom_loaders).delimiter
tabulator_source, tabulator_options = source.build_tabulator_stream_args()
with tabulator.Stream(tabulator_source, tabulator_options) as stream:
with tabulator.Stream(tabulator_source, **tabulator_options) as stream:
for row in stream:
if header is None:
header = ['' if v is None else v for v in row]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment