Rework with UI in mind
This commit is contained in:
parent
fbdb6f9f5a
commit
27fd95ba1e
4 changed files with 5 additions and 58 deletions
support_formatter/routes
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
import pathlib
|
||||
from typing import List
|
||||
from flask import send_from_directory
|
||||
import marshmallow as ma
|
||||
from flask_smorest.fields import Upload
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
@ -26,7 +25,7 @@ class MultipartFileSchema(ma.Schema):
|
|||
servantdata = Upload()
|
||||
cedata = Upload()
|
||||
|
||||
@blp.route("/", methods=["POST"])
|
||||
@blp.route("/upload", methods=["POST"])
|
||||
@blp.arguments(MultipartFormSchema, location="form")
|
||||
@blp.arguments(MultipartFileSchema, location="files")
|
||||
@blp.response(200)
|
||||
|
@ -39,7 +38,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
|
||||
for name, file in files.items():
|
||||
if name not in ("servantdata", "cedata"):
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html")
|
||||
return { "status": 406, "message": "Invalid form sent" }, 406
|
||||
|
||||
filepath = APISettings.FILE_SAVE_DIRECTORY / f"{uuid.uuid4()}.csv"
|
||||
file.save(filepath)
|
||||
|
@ -51,7 +50,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
filepaths.append(filepath)
|
||||
|
||||
if len(filepaths) == 0:
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html")
|
||||
return { "status": 406, "message": "No files provided" }, 406
|
||||
|
||||
try:
|
||||
for f in filepaths:
|
||||
|
@ -61,10 +60,6 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
except FileTypeInvalidError:
|
||||
for f in filepaths:
|
||||
f.unlink()
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html")
|
||||
return { "status": 500, "message": "Error whilst parsing uploaded file - please contact Firq on Fate/Sacc Order" }, 406
|
||||
|
||||
return returndata
|
||||
|
||||
@blp.route("/", methods=["GET"])
|
||||
def file_dialog():
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "index.html")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue