flaschengeist/geruecht/routes.py

47 lines
1.2 KiB
Python
Raw Normal View History

2019-01-13 19:07:46 +00:00
from flask import render_template, url_for, redirect, flash, jsonify
from geruecht import app, db
from geruecht.forms import RegistrationForm
from geruecht.model import User
users = [
{
'name': 'Corey Schafer',
'sum': '20€'
},
{
'name': 'Tim Gröger',
'sum': '10€'
},
{
'name': 'Franziska Bobbe',
'sum': '5,80€'
}
]
@app.route("/", methods=['GET', 'POST'])
@app.route("/home", methods=['GET', 'POST'])
def home():
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data)
db.session.add(user)
db.session.commit()
flash(f'Person wurde angelegt: {form.username.data}', 'success')
return redirect(url_for('home'))
return render_template('home.html', users=User.query.all(), form=form)
@app.route("/<string:username>/add-<int:value>", methods=['POST'])
def add(username, value):
user = User.query.filter_by(username=username).first()
user.add(value)
db.session.commit()
flash(f'{username} wurde {value}€ hinzugefügt', 'success')
return jsonify({'data': user.sum})
@app.route("/about")
def about():
return render_template('about.html', title='about')