Files
fioul/webapp.py

35 lines
737 B
Python

import os
from bottle import hook, request, route, run, static_file, view
import models
from models import Price
# ----------------------------------------------------------------------
# Web application
@route("/")
@view("search_results")
def results_page():
query = Price.select().order_by(Price.date.desc())
results = list(query)
return dict(results=results)
@route("/static/<filename>")
def serve_static_file(filename):
project_dir = os.path.dirname(__file__)
static_root = os.path.join(project_dir, "static")
return static_file(filename, root=static_root)
@hook("before_request")
def connect_to_db():
models.db.connect()
@hook("after_request")
def close_db_connection():
models.db.close()