diff --git a/static/fioul.css b/static/fioul.css new file mode 100644 index 0000000..58cab34 --- /dev/null +++ b/static/fioul.css @@ -0,0 +1,10 @@ +/* +tr.monday td { + border-bottom-width: 0.19rem; +} +*/ +tr.saturday, tr.sunday { + /* background-color: aliceblue; */ + background-color: var(--clight); + +} diff --git a/views/search_results.tpl b/views/search_results.tpl index 84f08b0..8bb7f33 100644 --- a/views/search_results.tpl +++ b/views/search_results.tpl @@ -2,16 +2,18 @@ Fioul +

Prix du m³ de fioul pour Languidic

% for x in results: - - - - + + + + + % end
{{x.date}}{{x.price}}
{{x.date.strftime('%A')}}{{x.date.strftime('%d %b %Y')}}{{x.price}}
diff --git a/webapp.py b/webapp.py index 3d154bd..9a15b6e 100644 --- a/webapp.py +++ b/webapp.py @@ -1,3 +1,4 @@ +import locale import os from bottle import hook, request, route, run, static_file, view @@ -14,7 +15,16 @@ from models import Price def results_page(): query = Price.select().order_by(Price.date.desc()) results = list(query) - return dict(results=results) + day_classes = { + 0: "monday", + 1: "tuesday", + 2: "wednesday", + 3: "thursday", + 4: "friday", + 5: "saturday", + 6: "sunday", + } + return dict(results=results, day_classes=day_classes) @route("/static/") @@ -24,6 +34,17 @@ def serve_static_file(filename): return static_file(filename, root=static_root) +@hook("before_request") +def set_locale(): + """Set the locale for all categories to the first lang in Accept-Language + header. Default to fr_FR.UTF-8 + """ + accept_language = request.get_header("Accept-Language", "fr-FR") + first_lang = accept_language.split(";")[0].split(",")[0] + lang = first_lang.translate(str.maketrans("-", "_")) + ".UTF-8" + locale.setlocale(locale.LC_ALL, lang) + + @hook("before_request") def connect_to_db(): models.db.connect()