transcription-files receives filesOverwrite status
import os
from pathlib import Path
-from flask import Blueprint, redirect, request, url_for, escape, jsonify
+from flask import Blueprint, redirect, request, url_for, escape
from werkzeug.utils import secure_filename
from ..blueprint import Blueprint
from . import comp
from ..paths import CURRENT_MODEL_DIR
+import json
bp = Blueprint("model", __name__, url_prefix="/model")
bp.register_blueprint(comp.bp)
-
@bp.route("/new")
def new():
# assuming that this would only be a POST?
this.models = state.Model()
return '{"status": "new model created"}'
+
@bp.route("/name", methods=['GET', 'POST'])
def name():
print(request.json['name'])
@@ -30,6 +31,7 @@ def name():
with open(file_path, 'r') as fin:
return f'{{ "name": "{fin.read()}" }}'
+
@bp.route("/date")
def date():
file_path = os.path.join(CURRENT_MODEL_DIR, 'date.txt')
@@ -42,6 +44,7 @@ def date():
with open(file_path, 'r') as fin:
return f'{{ "date": "{fin.read()}" }}'
+
@bp.route("/transcription-files", methods=['GET', 'POST'])
def transcription_files():
# setup the path
@@ -51,13 +54,26 @@ def transcription_files():
# handle incoming data
if request.method == 'POST':
+
+ # the request includes this filesOverwrite property
+ # use this to determine whether received files are
+ # appended to input data or overwrite input data
+
+ filesOverwrite = request.form["filesOverwrite"]
+ print('filesOverwrite:', filesOverwrite)
+
uploaded_files = request.files.getlist("file")
file_names = []
for file in uploaded_files:
print(f'file: {file}')
print(f'file name: {file.filename}')
file_names.append(file.filename)
- return jsonify(file_names)
+
+ # return just the received file names
+ # and let the GUI append or overwrite
+ # or else, send back the filenames of all input files
+ return json.dumps(file_names)
+
@bp.route("/pronunciation", methods=['POST'])
def pronunciation():
@@ -75,18 +91,22 @@ def pronunciation():
# return the state
# with open(file_path, 'r') as fin:
# return f'{{ "pronunciation": "{fin.read()}" }}'
+
return file.filename
-@bp.route("/settings")
+@bp.route("/settings", methods=['GET', 'POST'])
def settings():
file_path = os.path.join(CURRENT_MODEL_DIR, 'settings.txt')
if request.method == 'POST':
+ settings = request.json['settings']
+ print('settings', settings)
+
# update the state name
- with open(file_path, 'w') as fout:
- fout.write(request.json['settings'])
+ # with open(file_path, 'w') as fout:
+ # fout.write(setting)
# return the state
- with open(file_path, 'r') as fin:
- return f'{{ "settings": "{fin.read()}" }}'
-
+ # with open(file_path, 'r') as fin:
+ # return f'{fin.read()}'
+ return json.dumps(settings)
