From b357e084213993b541cedf9e2826cff25a36bf97 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Wed, 20 Nov 2024 21:57:56 +0100 Subject: [PATCH] Added instructions dropdown if downloaded --- app.py | 26 +++++- templates/index.html | 212 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 212 insertions(+), 26 deletions(-) diff --git a/app.py b/app.py index cfca150..c5699f0 100644 --- a/app.py +++ b/app.py @@ -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/',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/', 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('//', methods=['GET', 'POST']) def inventory(tmp,u_id): diff --git a/templates/index.html b/templates/index.html index 40dd241..286d003 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,5 @@ - +ns. @@ -82,7 +82,6 @@ -