Display results only for the current month
This commit is contained in:
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