Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Validata
Validata UI
Commits
bff8385e
Commit
bff8385e
authored
Jun 14, 2019
by
Pierre Dittgen
Browse files
Validate uploaded CSV file
parent
31d3acd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
validata_ui/validata_util.py
View file @
bff8385e
...
...
@@ -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
ipdb
.
set_trace
()
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
)
validata_ui/views.py
View file @
bff8385e
...
...
@@ -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
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment