Skip to content

Commit 3cdc87c

Browse files
committed
fix(csv): ensure CSV sidecar is saved as .json, add test sidecar, and export all dataset folder files to fix import/export
1 parent 985dd20 commit 3cdc87c

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def upload_file() -> flask.Response:
6464
flask.abort(400, "Filename is required")
6565
filename = werkzeug.utils.secure_filename(os.path.basename(file.filename))
6666
print(f"{filename=}", flush=True)
67-
file.save(os.path.join(UPLOAD_FOLDER, filename))
67+
file_path = os.path.join(UPLOAD_FOLDER, filename)
68+
file.save(file_path)
69+
if filename.lower().endswith(".csv.json"):
70+
shutil.copyfile(file_path, os.path.join(UPLOAD_FOLDER, filename[:-9] + ".json"))
6871
return flask.make_response({"message": "File uploaded"}, 201)
6972

7073

@@ -432,10 +435,11 @@ def export_project() -> flask.Response:
432435

433436
for data_id, native_file in rows:
434437
base_dir = os.path.join(project_folder, data_id)
435-
436-
native_path = os.path.join(base_dir, str(native_file))
437-
if os.path.isfile(native_path):
438-
zip_file.write(native_path, os.path.join(data_id, str(native_file)))
438+
if os.path.isdir(base_dir):
439+
for f_name in os.listdir(base_dir):
440+
file_path = os.path.join(base_dir, f_name)
441+
if os.path.isfile(file_path):
442+
zip_file.write(file_path, os.path.join(data_id, f_name))
439443

440444
zip_file.writestr("snapshot.json", flask.json.dumps(params.snapshot))
441445

tests/data/test.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"separator": ",",
3+
"header_row": 0,
4+
"first_row": 1,
5+
"x_column": 0,
6+
"y_column": 1,
7+
"z_column": 2,
8+
"headerRow": 0,
9+
"firstRow": 1,
10+
"xColumn": 0,
11+
"yColumn": 1,
12+
"zColumn": 2
13+
}

0 commit comments

Comments
 (0)