Add in version history for http functions
and also load .env in dev mode
This commit is contained in:
40
app.py
40
app.py
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
from flask import Flask, Response, jsonify, redirect, render_template, request, url_for
|
||||
from flask import Flask, Response, jsonify, redirect, render_template, render_template_string, request, url_for
|
||||
import jinja_partials
|
||||
from jinja2_fragments import render_block
|
||||
from flask_htmx import HTMX
|
||||
@@ -9,6 +9,12 @@ from db import DataBase
|
||||
from services import create_http_function_view_model, create_http_functions_view_model
|
||||
from flask_login import LoginManager, UserMixin, current_user, login_required, login_user, logout_user
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file in non-production environments
|
||||
if os.environ.get('FLASK_ENV') != 'production':
|
||||
load_dotenv()
|
||||
|
||||
login_manager = LoginManager()
|
||||
app = Flask(__name__)
|
||||
@@ -222,6 +228,38 @@ def client(function_id):
|
||||
return render_block(app.jinja_env, 'dashboard/http_functions/client.html', 'page', function_id=function_id, **http_function)
|
||||
return render_template("dashboard/http_functions/client.html", function_id=function_id, **http_function)
|
||||
|
||||
@app.route("/dashboard/http_functions/<int:function_id>/history", methods=["GET"])
|
||||
@login_required
|
||||
def get_http_function_history(function_id):
|
||||
user_id = current_user.id
|
||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
|
||||
name = http_function['name']
|
||||
version_number = http_function['version_number']
|
||||
|
||||
http_function_history = []
|
||||
if version_number > 1:
|
||||
raw_history = db.get_http_function_history(function_id)
|
||||
|
||||
for i in range(len(raw_history) - 1):
|
||||
pre_version = raw_history[i + 1]
|
||||
post_version = raw_history[i]
|
||||
|
||||
http_function_history.append({
|
||||
'pre': pre_version['script_content'],
|
||||
'post': post_version['script_content'],
|
||||
'version_id': post_version['version_id'],
|
||||
'version_number': post_version['version_number'],
|
||||
'updated_at': post_version['updated_at']
|
||||
})
|
||||
|
||||
|
||||
if htmx:
|
||||
return render_block(app.jinja_env, 'dashboard/http_functions/history.html', 'page', user_id=user_id, function_id=function_id, name=name, http_function=http_function, http_function_history=http_function_history)
|
||||
return render_template("dashboard/http_functions/history.html", user_id=user_id, name=name, function_id=function_id, http_function=http_function, http_function_history=http_function_history)
|
||||
|
||||
@ app.route("/dashboard/timer_functions", methods=["GET"])
|
||||
@login_required
|
||||
def dashboard_timer_functions():
|
||||
|
||||
Reference in New Issue
Block a user