From 326e76bae97a7e9607cf9e67928653bcfc7ba9b4 Mon Sep 17 00:00:00 2001 From: encrypt Date: Tue, 17 Oct 2023 22:37:02 +0200 Subject: [PATCH] =?UTF-8?q?modificato=20il=20sistema=20di=20gestione=20dei?= =?UTF-8?q?=20templates,=20ora=20un=20template=20=C3=A8=20fatto=20dal=20te?= =?UTF-8?q?mplate=20jinja=20+=20i=20parametri,=20aggiunto=20autoselect=20i?= =?UTF-8?q?n=20home?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 12 ++++++++---- templates.json | 29 +++++++++++++++++++++++++++++ templates/index.html | 19 ++++++++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 templates.json diff --git a/app.py b/app.py index 8c8c5cc..aaf50d6 100755 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ from flask import render_template, request app = Flask(__name__) gancio_instance = 'balotta.org' -templates = [x.stem for x in pathlib.Path('./templates/flyers/').glob("*.html")] +templates = json.load(open('./templates.json')) default_template = 'simple' events_ep = f'https://{gancio_instance}/api/events' @@ -60,10 +60,14 @@ def main(): def flyer(): relevant_events = request.args.getlist('events', type=int) template = request.args.get("template", default=default_template, type=str) - if template not in templates: + if template not in [ t['name'] for t in templates ]: return "template not found", 404 + template = [t for t in templates if t['name'] == template][0] events = fetch_events(events_ep) - events = [ e for e in events if e['id'] in relevant_events ] - return render_template(f'flyers/{template}.html', events=events) + events = [ e for e in events if e['id'] in relevant_events ] + params = {} + if 'params' in template: + params = template['params'] + return render_template(f'flyers/{template["baseTemplate"]}.html', events=events, params=params) diff --git a/templates.json b/templates.json new file mode 100644 index 0000000..e2bcb89 --- /dev/null +++ b/templates.json @@ -0,0 +1,29 @@ +[ + { + "name": "simple", + "baseTemplate": "simple", + "paperSize": "A3", + "maxEvents": 24, + "pages": 1, + "params": { + "colorMode": "black" + } + }, + { + "name": "simple-white", + "baseTemplate": "simple", + "paperSize": "A3", + "maxEvents": 24, + "pages": 1, + "params": { + "colorMode": "white" + } + }, + { + "name": "asymmetric", + "baseTemplate": "asymmetric", + "paperSize": "A3", + "maxEvents": 24, + "pages": 1 + } +] diff --git a/templates/index.html b/templates/index.html index a8ed37a..2255083 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,15 +10,28 @@ L'attuale layout può contenere fino a 24 eventi.
- {% for template in templates %} - + {% endfor %}
{% for event in events %} - +
{% endfor %}
+ +