Show dates in more readable way in webapp
This commit is contained in:
10
static/fioul.css
Normal file
10
static/fioul.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
tr.monday td {
|
||||||
|
border-bottom-width: 0.19rem;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
tr.saturday, tr.sunday {
|
||||||
|
/* background-color: aliceblue; */
|
||||||
|
background-color: var(--clight);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,14 +2,16 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Fioul</title>
|
<title>Fioul</title>
|
||||||
<link rel="stylesheet" href="/static/classless.css">
|
<link rel="stylesheet" href="/static/classless.css">
|
||||||
|
<link rel="stylesheet" href="/static/fioul.css">
|
||||||
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Prix du m³ de fioul pour Languidic</h1>
|
<h1>Prix du m³ de fioul pour Languidic</h1>
|
||||||
<table id="results" class="u-full-width">
|
<table id="results" class="u-full-width">
|
||||||
% for x in results:
|
% for x in results:
|
||||||
<tr>
|
<tr class="{{day_classes[x.date.weekday()]}}">
|
||||||
<td>{{x.date}}</td>
|
<td>{{x.date.strftime('%A')}}</td>
|
||||||
|
<td>{{x.date.strftime('%d %b %Y')}}</td>
|
||||||
<td>{{x.price}}</td>
|
<td>{{x.price}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
% end
|
% end
|
||||||
|
|||||||
23
webapp.py
23
webapp.py
@@ -1,3 +1,4 @@
|
|||||||
|
import locale
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bottle import hook, request, route, run, static_file, view
|
from bottle import hook, request, route, run, static_file, view
|
||||||
@@ -14,7 +15,16 @@ from models import Price
|
|||||||
def results_page():
|
def results_page():
|
||||||
query = Price.select().order_by(Price.date.desc())
|
query = Price.select().order_by(Price.date.desc())
|
||||||
results = list(query)
|
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>")
|
@route("/static/<filename>")
|
||||||
@@ -24,6 +34,17 @@ def serve_static_file(filename):
|
|||||||
return static_file(filename, root=static_root)
|
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")
|
@hook("before_request")
|
||||||
def connect_to_db():
|
def connect_to_db():
|
||||||
models.db.connect()
|
models.db.connect()
|
||||||
|
|||||||
Reference in New Issue
Block a user