Add edit form for http functions
This commit is contained in:
21
app.py
21
app.py
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from flask import Flask, Response, jsonify, render_template, request
|
||||
from flask import Flask, Response, jsonify, redirect, render_template, request, url_for
|
||||
import jinja_partials
|
||||
from jinja2_fragments import render_block
|
||||
from flask_htmx import HTMX
|
||||
@@ -94,6 +94,25 @@ def create_http_function():
|
||||
db.create_new_http_function(name, script_content)
|
||||
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():
|
||||
name = request.args.get('name')
|
||||
http_function = db.get_http_function(name)
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
script = http_function['script_content']
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script)
|
||||
|
||||
@ app.route("/dashboard/http_functions/edit", methods=["POST"])
|
||||
def edit_http_function():
|
||||
try:
|
||||
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'))
|
||||
except Exception as e:
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script_content)
|
||||
|
||||
@ app.route("/dashboard/timer_functions", methods=["GET"])
|
||||
def dashboard_timer_functions():
|
||||
return render_template("dashboard/timer_functions.html")
|
||||
|
||||
Reference in New Issue
Block a user