Show dates in more readable way in webapp
This commit is contained in:
23
webapp.py
23
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/<filename>")
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user