Added instructions dropdown if downloaded

This commit is contained in:
2024-11-20 21:57:56 +01:00
parent 665649a33c
commit b357e08421
2 changed files with 212 additions and 26 deletions

26
app.py
View File

@@ -1,4 +1,4 @@
from flask import Flask, request, redirect, jsonify, render_template, Response,url_for
from flask import Flask, request, redirect, jsonify, render_template, Response,url_for, send_from_directory
import os
import json
from flask_socketio import SocketIO
@@ -22,6 +22,9 @@ app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1, x_
socketio = SocketIO(app,cors_allowed_origins=os.getenv("DOMAIN_NAME"))
count = 0
DIRECTORY = os.path.join(os.getcwd(), 'static', 'instructions')
@app.route('/favicon.ico')
# SocketIO event handler for client connection
@@ -67,6 +70,11 @@ def start_task(data):
#return redirect('/')
def hyphen_split(a):
if a.count("-") == 1:
return a.split("-")[0]
return "-".join(a.split("-", 2)[:2])
@app.route('/delete/<tmp>',methods=['POST', 'GET'])
def delete(tmp):
@@ -525,7 +533,13 @@ def index():
cursor.close()
conn.close()
return render_template('index.html',set_list=set_list,themes_list=theme_file,missing_list=missing_list)
files = [f for f in os.listdir(DIRECTORY) if f.endswith('.pdf')]
#files = [re.match(r'^([\w]+-[\w]+)', f).group() for f in os.listdir(DIRECTORY) if f.endswith('.pdf')]
print(files.sort())
return render_template('index.html',set_list=set_list,themes_list=theme_file,missing_list=missing_list,files=files)
if request.method == 'POST':
set_num = request.form.get('set_num')
@@ -579,6 +593,14 @@ def index():
return ('', 204)
# Route to serve individual files
@app.route('/files/<path:filename>', methods=['GET'])
def serve_file(filename):
try:
return send_from_directory(DIRECTORY, filename)
except Exception as e:
return jsonify({'error': str(e)}), 404
@app.route('/<tmp>/<u_id>', methods=['GET', 'POST'])
def inventory(tmp,u_id):