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.