initial commit
This commit is contained in:
33
app.py
Normal file
33
app.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
from flask import Flask, render_template, redirect, url_for, request
|
||||
|
||||
from peewee import fn
|
||||
|
||||
from model import Rides, connect
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
db_path = os.getenv("WIE_RIJD_DB", 'wie_rijd.db')
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
nrides = fn.COUNT(Rides.date).alias('amount')
|
||||
amounts = Rides.select(Rides.name, nrides).group_by(Rides.name).order_by(nrides.desc())
|
||||
|
||||
return render_template('list.html', title="hello", persons=amounts)
|
||||
|
||||
|
||||
@app.route('/add', methods=["POST"])
|
||||
def add_entry():
|
||||
Rides.create(name=request.form.get('name'))
|
||||
return redirect(url_for('root'))
|
||||
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
connect(db_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
Reference in New Issue
Block a user