diff --git a/src/anki_creator_flask/__init__.py b/src/anki_creator_flask/__init__.py index 34aa57f..bce9e1f 100644 --- a/src/anki_creator_flask/__init__.py +++ b/src/anki_creator_flask/__init__.py @@ -31,7 +31,7 @@ def create_app(): app.config.from_pyfile("config.py", silent=True) for blueprint in (homescreen, mainapp): - # for blueprint in (homescreen,): + # for blueprint in (homescreen,): app.register_blueprint(blueprint) return app diff --git a/src/anki_creator_flask/mainapp.py b/src/anki_creator_flask/mainapp.py index 5dfcff6..8c6a2a0 100644 --- a/src/anki_creator_flask/mainapp.py +++ b/src/anki_creator_flask/mainapp.py @@ -3,7 +3,7 @@ from pathlib import Path # Pip from anki_hsk_creator import api -from anki_hsk_creator.constants import DICT_TYPE, PHRASES_TYPE +from anki_hsk_creator.constants import DICTATION_TYPE, DICT_TYPE, PHRASES_TYPE from anki_hsk_creator.utility import ProcessFile from flask import ( Blueprint, @@ -27,33 +27,44 @@ mainapp = Blueprint( @mainapp.route("/", methods=["GET"]) def app(): """Main app entry pages""" - return render_template("app.html") + return redirect(url_for("mainapp.file_list")) + # return render_template("app.html") -@mainapp.route("/list", methods=["GET"]) -@mainapp.route("/list/", methods=["GET"]) -@mainapp.route("/list/", methods=["GET"]) +@mainapp.route("/list", methods=["GET", "POST", "DELETE"]) +@mainapp.route("/list/", methods=["GET", "POST", "DELETE"]) +@mainapp.route("/list/", methods=["GET", "POST", "DELETE"]) def file_list(listing_path=""): """Path for file lister""" - listing_path = Path(listing_path) - root_files = {file: [] for file in api.list_input_files()} - level = root_files - level_path = Path() - for part in listing_path.parts: - level_path = level_path / part - level[level_path] = {file: [] for file in api.list_input_files(level_path)} - level = level[level_path] + if request.method == "GET": + listing_path = Path(listing_path) + root_files = {file: [] for file in api.list_input_files()} + level = root_files + level_path = Path() + for part in listing_path.parts: + level_path = level_path / part + level[level_path] = {file: [] for file in api.list_input_files(level_path)} + level = level[level_path] - if listing_path: - file_data = api.analize_input_files(listing_path) - else: - file_data = api.analize_input_files(None) - return render_template( - "file_list.html", - file_data=file_data, - root_files=root_files, - listing_path=listing_path, - ) + if listing_path: + file_data = api.analize_input_files(listing_path) + else: + file_data = api.analize_input_files(None) + return render_template( + "file_list.html", + file_data=file_data, + root_files=root_files, + listing_path=listing_path, + ) + if request.method == "POST": + form = request.form.to_dict() + listing_path = Path(listing_path) + process_file = ProcessFile(listing_path) + if process_file.absolute_input_file.is_file(): + listing_path = listing_path.parent + return redirect( + (url_for("mainapp.create", listing_path=listing_path / form["name"])) + ) @mainapp.route("/download/", methods=["GET"]) @@ -127,6 +138,13 @@ def create(listing_path=""): ) response.set_cookie("download_started", "true", max_age=10) return response + elif args["deck_type"] in DICTATION_TYPE: + final_file = api.process_a_dictation_file(process_file, args["language_id"]) + response = make_response( + send_from_directory(final_file.parent, final_file.name) + ) + response.set_cookie("download_started", "true", max_age=10) + return response @mainapp.route("/process/", methods=["GET", "POST"]) diff --git a/src/anki_creator_flask/templates/create.html b/src/anki_creator_flask/templates/create.html index 52b9aa0..46d59d8 100644 --- a/src/anki_creator_flask/templates/create.html +++ b/src/anki_creator_flask/templates/create.html @@ -83,7 +83,7 @@
-

Loading, please wait...

+

Loading, creating audios, please wait...

@@ -151,7 +151,7 @@ type="radio" id="type3" name="deck_type" - value="paragraph" + value="dictation" /> diff --git a/src/anki_creator_flask/templates/file_list.html b/src/anki_creator_flask/templates/file_list.html index 8182451..1e59bc4 100644 --- a/src/anki_creator_flask/templates/file_list.html +++ b/src/anki_creator_flask/templates/file_list.html @@ -107,8 +107,22 @@

Current Path: {{ listing_path or "-" }}

+
  • +
    +
    + + + +
    +
    +
    Input files:
      {% for file in file_data['input'] %}