From 8472fc4c0de57d22d21f527afd213385d4c759ae Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sat, 10 Dec 2022 13:16:22 +0100 Subject: [PATCH] Add maintenance page with button to scrub temporary tags --- server/app.py | 11 +++++++++++ .../entertainment_decider/models/entities.py | 5 +++++ server/templates/maintenance/main.htm | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 server/templates/maintenance/main.htm diff --git a/server/app.py b/server/app.py index 9572f7c..975ef3f 100644 --- a/server/app.py +++ b/server/app.py @@ -752,6 +752,11 @@ def recommend_adaptive() -> ResponseReturnValue: return resp +@flask_app.route("/maintenance") +def maintenance_page() -> ResponseReturnValue: + return render_template("maintenance/main.htm") + + def cookies_rating(negative: bool) -> ResponseReturnValue: media_id = request.form.get("media_id", default=None, type=str) element = MediaElement.get(id=media_id) if media_id else None @@ -1355,3 +1360,9 @@ def api_media_set_dependent() -> ResponseReturnValue: for last, cur in common.iter_lookahead(common.fix_iter(elements)): last.is_blocking.add(cur) return redirect_back_or_okay() + + +@flask_app.route("/api/tag/delete_temporary", methods=["POST"]) +def api_tag_delete_temporary() -> ResponseReturnValue: + Tag.scrub_temporary_tags() + return redirect_back_or_okay() diff --git a/server/entertainment_decider/models/entities.py b/server/entertainment_decider/models/entities.py index c588bd8..b676816 100644 --- a/server/entertainment_decider/models/entities.py +++ b/server/entertainment_decider/models/entities.py @@ -175,6 +175,11 @@ class Tag(db.Entity, Tagable): use_for_preferences=True, ) + @classmethod + def scrub_temporary_tags(cls) -> int: + """Scrubs all temporary tags, which where left over because of errors.""" + count = orm.delete(tag for tag in cls if tag.notes == TEMPORARY_TAGS_IDENTIFIER) + return count if isinstance(count, int) else 0 id: int = orm.PrimaryKey(int, auto=True) diff --git a/server/templates/maintenance/main.htm b/server/templates/maintenance/main.htm new file mode 100644 index 0000000..09d1a1b --- /dev/null +++ b/server/templates/maintenance/main.htm @@ -0,0 +1,18 @@ +{% import "macros.htm" as macros %} + + + {% set title = "Maintenance" %} + + + {{ title }} + {{ macros.shared_style() }} + + + {{ macros.body_header() }} +

{{ title }}

+ {% set api_uri = "/api" %} +
+ {{ macros.no_input_post_form(api_uri + "/tag/delete_temporary", "delete temporary tags") }} +
+ +