From 654846047884f0f033e552da72462093992fe768 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 26 Sep 2025 14:18:14 +0200 Subject: [PATCH] add event details page, refacto templates --- oedb/resources/demo.py | 74 +++------ .../demo/templates/event_details.html | 45 ++++++ oedb/resources/demo/templates/layout.html | 51 ++++++ oedb/resources/demo/templates/stats.html | 146 +++++++++--------- 4 files changed, 191 insertions(+), 125 deletions(-) create mode 100644 oedb/resources/demo/templates/event_details.html create mode 100644 oedb/resources/demo/templates/layout.html diff --git a/oedb/resources/demo.py b/oedb/resources/demo.py index 09730c2..827b7ae 100644 --- a/oedb/resources/demo.py +++ b/oedb/resources/demo.py @@ -18,6 +18,19 @@ class DemoResource: Handles the /demo endpoint and related demo pages. """ + def __init__(self): + """ + Initialize the resource with a Jinja2 environment. + """ + # Set up Jinja2 environment + import jinja2 + import os + template_dir = os.path.join(os.path.dirname(__file__), 'demo', 'templates') + self.jinja_env = jinja2.Environment( + loader=jinja2.FileSystemLoader(template_dir), + autoescape=jinja2.select_autoescape(['html', 'xml']) + ) + def on_get_edit(self, req, resp, id=None): """ Handle GET requests to the /demo/edit endpoint. @@ -1995,63 +2008,22 @@ class DemoResource: Show a map with the event location and a table of its properties. """ import requests + import json logger.info(f"Processing GET request to /demo/by_id/{id}") try: resp.content_type = 'text/html' r = requests.get(f"https://api.openeventdatabase.org/event/{id}") r.raise_for_status() feature = r.json() - html = f""" - - - - - - Event {id} - OpenEventDatabase - - - - - -
- -

Évènement {id}

-
- - - - {''.join([f'' for k,v in sorted((feature.get('properties') or {{}}).items())])} - -
CléValeur
{k}{(v if not isinstance(v, dict) else str(v))}
-
- - - - """ + + # Load and render the template + template = self.jinja_env.get_template('event_details.html') + html = template.render( + id=id, + feature_json=json.dumps(feature), + properties=feature.get('properties') or {} + ) + resp.text = html resp.status = falcon.HTTP_200 logger.success(f"Successfully processed GET request to /demo/by_id/{id}") diff --git a/oedb/resources/demo/templates/event_details.html b/oedb/resources/demo/templates/event_details.html new file mode 100644 index 0000000..03d77e3 --- /dev/null +++ b/oedb/resources/demo/templates/event_details.html @@ -0,0 +1,45 @@ +{% extends "layout.html" %} + +{% block title %}Event {{ id }} - OpenEventDatabase{% endblock %} + +{% block css %} + +{% endblock %} + +{% block header %}Évènement {{ id }}{% endblock %} + +{% block content %} +
+ + + + {% for key, value in properties.items()|sort %} + + + + + {% endfor %} + +
CléValeur
{{ key }}{{ value }}
+{% endblock %} + +{% block scripts %} + +{% endblock %} \ No newline at end of file diff --git a/oedb/resources/demo/templates/layout.html b/oedb/resources/demo/templates/layout.html new file mode 100644 index 0000000..7e7126b --- /dev/null +++ b/oedb/resources/demo/templates/layout.html @@ -0,0 +1,51 @@ + + + + + + {% block title %}OpenEventDatabase{% endblock %} + + + + + + {% block css %}{% endblock %} + + + + + + + + {% block head %}{% endblock %} + + +
+ + {% include 'partials/demo_nav.html' %} + + +
+

{% block header %}OpenEventDatabase{% endblock %}

+
+ + +
+ {% block content %}{% endblock %} +
+ + + +
+ + + + + + {% block scripts %}{% endblock %} + + \ No newline at end of file diff --git a/oedb/resources/demo/templates/stats.html b/oedb/resources/demo/templates/stats.html index 7062504..7422378 100644 --- a/oedb/resources/demo/templates/stats.html +++ b/oedb/resources/demo/templates/stats.html @@ -1,76 +1,74 @@ - - - - - - Stats par type - OpenEventDatabase - - - - -
- {% include 'partials/demo_nav.html' %} -

Statistiques par type d'évènement (what)

-

Total: {{ total_events }} évènements

- - - - - - - - - - {% for what, count in counts %} - - - - - - {% endfor %} - -
Type (what)NombreActions
{{ what }}{{ count }} - Voir JSON - Voir sur la carte -
+{% extends "layout.html" %} - {% if selected_what %} -

Carte: {{ selected_what }}

- - -
- - {% endif %} -
- - +{% block title %}Stats par type - OpenEventDatabase{% endblock %} + +{% block css %} + +{% endblock %} + +{% block header %}Statistiques par type d'évènement (what){% endblock %} + +{% block content %} +

Total: {{ total_events }} évènements

+ + + + + + + + + + {% for what, count in counts %} + + + + + + {% endfor %} + +
Type (what)NombreActions
{{ what }}{{ count }} + Voir JSON + Voir sur la carte +
+ +{% if selected_what %} +

Carte: {{ selected_what }}

+
+{% endif %} +{% endblock %} + +{% block scripts %} +{% if selected_what %} + +{% endif %} +{% endblock %}