Display results only for the current month
This commit is contained in:
@@ -8,6 +8,11 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Prix du m³ de fioul pour Languidic</h1>
|
<h1>Prix du m³ de fioul pour Languidic</h1>
|
||||||
|
<h2 class="row">
|
||||||
|
<div class="col-3"><a href="{{ prev_page }}">[<]</a></div>
|
||||||
|
<div class="col-3" style="text-align:center">{{ displayed_month }}</div>
|
||||||
|
<div class="col-3" style="text-align:right"><a href="{{ next_page }}">[>]</a></div>
|
||||||
|
</h2>
|
||||||
<table id="results" class="u-full-width">
|
<table id="results" class="u-full-width">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2"></th> <!-- Date -->
|
<th colspan="2"></th> <!-- Date -->
|
||||||
@@ -19,7 +24,7 @@
|
|||||||
<td>{{current_1000}}</td>
|
<td>{{current_1000}}</td>
|
||||||
<td>{{current_500}}</td>
|
<td>{{current_500}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
% for x in results:
|
% for x in month_results:
|
||||||
<tr class="{{day_classes[x.date.weekday()]}}">
|
<tr class="{{day_classes[x.date.weekday()]}}">
|
||||||
<td>{{x.date.strftime('%A')}}</td>
|
<td>{{x.date.strftime('%A')}}</td>
|
||||||
<td>{{x.date.strftime('%d %b %Y')}}</td>
|
<td>{{x.date.strftime('%d %b %Y')}}</td>
|
||||||
|
|||||||
32
webapp.py
32
webapp.py
@@ -1,7 +1,9 @@
|
|||||||
|
import datetime as dt
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bottle import hook, request, route, run, static_file, view
|
from bottle import hook, redirect, request, route, run, static_file, view
|
||||||
|
from dateutil.relativedelta import *
|
||||||
|
|
||||||
import models
|
import models
|
||||||
from fioul import get_today_prices_from_internet
|
from fioul import get_today_prices_from_internet
|
||||||
@@ -12,9 +14,31 @@ from models import Price
|
|||||||
|
|
||||||
|
|
||||||
@route("/")
|
@route("/")
|
||||||
|
def home():
|
||||||
|
today = dt.date.today()
|
||||||
|
return redirect(f"/{today.year}/{today.month}")
|
||||||
|
|
||||||
|
|
||||||
|
@route("/<year:int>/<month:int>")
|
||||||
@view("search_results", template_settings={"noescape": True})
|
@view("search_results", template_settings={"noescape": True})
|
||||||
def results_page():
|
def results_page(year, month):
|
||||||
results = Price.select().order_by(Price.date.desc())
|
results = Price.select().order_by(Price.date.desc())
|
||||||
|
start = dt.date(year, month, day=1)
|
||||||
|
prev = start + relativedelta(months=-1)
|
||||||
|
next = start + relativedelta(months=+1)
|
||||||
|
print(f"debug upper date boundary: {start + relativedelta(months=1)}")
|
||||||
|
month_results = (
|
||||||
|
Price.select()
|
||||||
|
.where(
|
||||||
|
Price.date >= start,
|
||||||
|
Price.date < next,
|
||||||
|
)
|
||||||
|
.order_by(Price.date.desc())
|
||||||
|
)
|
||||||
|
prev_page = f"/{prev.year}/{prev.month}"
|
||||||
|
next_page = f"/{next.year}/{next.month}"
|
||||||
|
displayed_month = start.strftime("%B %Y")
|
||||||
|
print(f"year: {year}, month: {month}, displayed: {displayed_month}")
|
||||||
current_500, current_1000 = get_today_prices_from_internet()
|
current_500, current_1000 = get_today_prices_from_internet()
|
||||||
day_classes = {
|
day_classes = {
|
||||||
0: "monday",
|
0: "monday",
|
||||||
@@ -27,6 +51,10 @@ def results_page():
|
|||||||
}
|
}
|
||||||
return dict(
|
return dict(
|
||||||
results=results,
|
results=results,
|
||||||
|
month_results=month_results,
|
||||||
|
prev_page=prev_page,
|
||||||
|
next_page=next_page,
|
||||||
|
displayed_month=displayed_month,
|
||||||
day_classes=day_classes,
|
day_classes=day_classes,
|
||||||
current_500=current_500,
|
current_500=current_500,
|
||||||
current_1000=current_1000,
|
current_1000=current_1000,
|
||||||
|
|||||||
Reference in New Issue
Block a user