Add ability to delete http functions

This commit is contained in:
Peter Stockings
2023-12-16 22:35:28 +11:00
parent 2365fa3987
commit 204000a668
5 changed files with 97 additions and 34 deletions

31
app.py
View File

@@ -89,10 +89,16 @@ def get_http_function_add_form():
@ app.route("/dashboard/http_functions/create", methods=["POST"])
def create_http_function():
name = request.json.get('name')
script_content = request.json.get('script_content')
db.create_new_http_function(name, script_content)
return render_template("dashboard/http_functions/new.html", name=name, script=script_content)
try:
name = request.json.get('name')
script_content = request.json.get('script_content')
db.create_new_http_function(name, script_content)
http_functions = db.get_http_functions()
http_functions = create_http_functions_view_model(http_functions)
return render_template("dashboard/http_functions.html", http_functions=http_functions)
except Exception as e:
return render_template("dashboard/http_functions/new.html", name=name, script=script_content)
@ app.route("/dashboard/http_functions/edit_form", methods=["GET"])
def get_http_function_edit_form():
@@ -109,10 +115,25 @@ def edit_http_function():
name = request.json.get('name')
script_content = request.json.get('script_content')
db.edit_http_function(name, script_content)
return redirect(url_for('dashboard_http_functions'))
http_functions = db.get_http_functions()
http_functions = create_http_functions_view_model(http_functions)
return render_template("dashboard/http_functions.html", http_functions=http_functions)
except Exception as e:
return render_template("dashboard/http_functions/edit.html", name=name, script=script_content)
@ app.route("/dashboard/http_functions/delete", methods=["DELETE"])
def delete_http_function():
try:
name = request.args.get('name')
db.delete_http_function(name)
http_functions = db.get_http_functions()
http_functions = create_http_functions_view_model(http_functions)
return render_template("dashboard/http_functions.html", http_functions=http_functions)
except Exception as e:
return jsonify({'error': str(e)}), 500
@ app.route("/dashboard/timer_functions", methods=["GET"])
def dashboard_timer_functions():
return render_template("dashboard/timer_functions.html")