Display results only for the current month
This commit is contained in:
@@ -8,6 +8,11 @@
|
||||
</head>
|
||||
<body>
|
||||
<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">
|
||||
<tr>
|
||||
<th colspan="2"></th> <!-- Date -->
|
||||
@@ -19,7 +24,7 @@
|
||||
<td>{{current_1000}}</td>
|
||||
<td>{{current_500}}</td>
|
||||
</tr>
|
||||
% for x in results:
|
||||
% for x in month_results:
|
||||
<tr class="{{day_classes[x.date.weekday()]}}">
|
||||
<td>{{x.date.strftime('%A')}}</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 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
|
||||
from fioul import get_today_prices_from_internet
|
||||
@@ -12,9 +14,31 @@ from models import Price
|
||||
|
||||
|
||||
@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})
|
||||
def results_page():
|
||||
def results_page(year, month):
|
||||
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()
|
||||
day_classes = {
|
||||
0: "monday",
|
||||
@@ -27,6 +51,10 @@ def results_page():
|
||||
}
|
||||
return dict(
|
||||
results=results,
|
||||
month_results=month_results,
|
||||
prev_page=prev_page,
|
||||
next_page=next_page,
|
||||
displayed_month=displayed_month,
|
||||
day_classes=day_classes,
|
||||
current_500=current_500,
|
||||
current_1000=current_1000,
|
||||
|
||||
Reference in New Issue
Block a user