summaryrefslogtreecommitdiff
path: root/app/views/expenses.py
diff options
context:
space:
mode:
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)