summaryrefslogtreecommitdiff
path: root/app/views/expenses.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2013-04-14 18:54:50 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2013-04-14 18:54:50 +0200
commit21c591327c8c4c8bbf34831a23f4439fec32f3b2 (patch)
tree68754e3f4726d31c7a61a472fa17109a5b316295 /app/views/expenses.py
parentabfc1005db0f256ca60823f61b8a904304eb9a4c (diff)
downloadkosten-21c591327c8c4c8bbf34831a23f4439fec32f3b2.tar.gz
kosten-21c591327c8c4c8bbf34831a23f4439fec32f3b2.tar.bz2
kosten-21c591327c8c4c8bbf34831a23f4439fec32f3b2.zip
Add expense -- in Flask
Diffstat (limited to '')
-rw-r--r--app/views/expenses.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/app/views/expenses.py b/app/views/expenses.py
index 6b976de..da01308 100644
--- a/app/views/expenses.py
+++ b/app/views/expenses.py
@@ -1,10 +1,12 @@
from flask import Blueprint
-from flask import render_template, request, url_for
+from flask import render_template, request, url_for, redirect
import datetime, decimal
from sqlalchemy import sql, func
-from ..model import Category, SingleExpense, CatExpense, MonthExpense
+from ..model import db, Category, SingleExpense, CatExpense, MonthExpense
+
+from ..forms import ExpenseForm
mod = Blueprint('expenses', __name__)
@@ -71,6 +73,19 @@ def show(year = None, month = None):
def edit(id):
return render_template("page.jinja")
-@mod.route("/add/")
+@mod.route("/add/", methods=("GET", "POST"))
def add():
- return render_template("page.jinja")
+ form = ExpenseForm()
+ form.category.query = Category.query.order_by("name")
+
+ if form.validate_on_submit():
+ se = SingleExpense()
+
+ form.populate_obj(se)
+
+ db.session.add(se)
+ db.session.commit()
+
+ return redirect(url_for("index"))
+
+ return render_template("pages/add.jinja", form=form)