Skip to content

Add route for importing data from UI#150

Merged
arnaudfnr merged 11 commits intomainfrom
feat/add-route-import
May 5, 2026
Merged

Add route for importing data from UI#150
arnaudfnr merged 11 commits intomainfrom
feat/add-route-import

Conversation

@OlivierCoen
Copy link
Copy Markdown
Collaborator

@OlivierCoen OlivierCoen commented Apr 30, 2026

Closes #109

  • Add URL map/add-data/
  • Made associated view that parses a POST request with :
    • file uploaded
    • package
    • action
  • added test

@OlivierCoen OlivierCoen requested a review from arnaudfnr April 30, 2026 12:05
Comment thread backend/maps/tests.py
)

self.assertEqual(response.status_code, 200)
self.assertIn('File uploaded successfully', response.json()['message'])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also assert the filename

Comment thread backend/maps/views.py Outdated
# NOTE: we do not use FileSystemStorage here, as it creates file name contanining both lower and upper case letters
# but pydantic does not accept upper case letters in file names
# furthermore, a temp file is more appropriate here because it is deleted automatically after context manager exits
with NamedTemporaryFile(suffix=uploaded_file_suffix) as temp_file:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had an issue with file-encoding, one of the csv we received from all4Trees was not utf-8 and an error was raised. I had to manually convert the csv file into utf-8 enconding to make it work.
Might be interesting to add enconding detection using chardet : https://github.com/chardet/chardet and convert every file to utf-8 before reading it (or add the detected encoding to the reader if more simple)

Comment thread backend/maps/views.py Outdated
# furthermore, a temp file is more appropriate here because it is deleted automatically after context manager exits
with NamedTemporaryFile(suffix=uploaded_file_suffix) as temp_file:
temp_file.write(uploaded_file.read())
file = Path(temp_file.name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename does not seems right. I get this : tmpzpc8sbht.csv

Suggested change
file = Path(temp_file.name)
file = Path(uploaded_file.name)

@OlivierCoen OlivierCoen force-pushed the feat/add-route-import branch from 2013e4c to d276449 Compare May 4, 2026 18:24
@arnaudfnr arnaudfnr merged commit 9f179ad into main May 5, 2026
5 checks passed
@arnaudfnr arnaudfnr deleted the feat/add-route-import branch May 5, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add route to import new data into a datapackage

2 participants