diff --git a/app.py b/app.py index f348924..d450ef2 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, jsonify, request, render_template +from flask import Flask, jsonify, request, render_template, redirect import json import os @@ -29,8 +29,8 @@ app = Flask(__name__) @app.route("/", methods=["GET"]) def home(): - html = "

Home page API REST Compiti

ciao, 3cx merda

" - html += "Documentazione" + html = "

Home page API REST Compiti

" + html += "Apri interfaccia web
Documentazione" return html, 200 @app.route("/doc", methods=["GET"]) @@ -68,4 +68,46 @@ def delete_compito(id): update_file() return jsonify([]), 404 +@app.route("/ui") +def web_ui(): + # Tabella compiti + html = "" + for ciscomerda in compiti: + html += "" + html += f"" + html += "
{ciscomerda["descrizione"]}Elimina" + html += "
" + + html += "
" + html += "" + html += "" + html += "
" + + return html, 200 + +@app.route("/form_add") +def form_add(): + if not request.args.get("descrizione"): + return "Errore: descrizione mancante", 400 + else: + global id_counter + d = request.args.get("descrizione") + compiti.append({"id": id_counter, "descrizione": d}) + id_counter += 1 + update_file() + return redirect("/ui") + +@app.route("/form_delete") +def form_delete(): + if not request.args.get("id"): + return "Errore: id mancante", 400 + else: + id = int(request.args.get("id")) + for ciscomerda in compiti: + if ciscomerda["id"] == id: + compiti.remove(ciscomerda) + update_file() + return redirect("/ui") + return "Errore: compito non trovato", 404 + app.run("0.0.0.0")