summaryrefslogtreecommitdiff
path: root/app/views/consts.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2013-10-14 23:50:27 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2013-10-14 23:50:27 +0200
commitdbb134751c3a87cf203cd243b1952b146b8914c1 (patch)
treecb34abe63bd1e3f95a4616b4a20a7528380014f1 /app/views/consts.py
parenta628fd3084e94959dc29c86912f2a2e97038799c (diff)
downloadkosten-dbb134751c3a87cf203cd243b1952b146b8914c1.tar.gz
kosten-dbb134751c3a87cf203cd243b1952b146b8914c1.tar.bz2
kosten-dbb134751c3a87cf203cd243b1952b146b8914c1.zip
Finish login stuff
Diffstat (limited to 'app/views/consts.py')
-rw-r--r--app/views/consts.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/app/views/consts.py b/app/views/consts.py
index dab02e0..8eef73b 100644
--- a/app/views/consts.py
+++ b/app/views/consts.py
@@ -5,6 +5,7 @@ import datetime
from sqlalchemy import sql
from ..model import db, Category, ConstExpense
+from ..login import current_user, login_required
from ..forms import ConstForm, today
from ..utils import templated, redirect
@@ -13,7 +14,7 @@ mod = Blueprint('consts', __name__)
def const_form(cur=None, obj=None):
obj = cur if obj is None else obj
form = ConstForm(obj=obj)
- form.category.query = Category.query.order_by(Category.name)
+ form.category.query = Category.of(current_user).order_by(Category.name)
# init prev_list
CE = ConstExpense
@@ -24,16 +25,17 @@ def const_form(cur=None, obj=None):
filter = sql.or_(CE.next == cur, filter)
filter = sql.and_(filter, CE.id != cur.id)
- form.prev.query = CE.query.filter(filter).order_by(CE.description)
+ form.prev.query = CE.of(current_user).filter(filter).order_by(CE.description)
return form
@mod.route("/")
+@login_required
@templated()
def list ():
d = today()
- expenses = ConstExpense.query.order_by(ConstExpense.description).all()
+ expenses = ConstExpense.of(current_user).order_by(ConstExpense.description).all()
current = []
old = []
@@ -51,11 +53,13 @@ def list ():
return { 'current': current, 'old': old, 'future': future }
@mod.route("/<int:id>")
+@login_required
@templated()
def show(id):
return { 'exp': ConstExpense.get(id) }
@mod.route("/edit/<int:id>", methods=("GET", "POST"))
+@login_required
@templated()
def edit(id):
exp = ConstExpense.get(id)
@@ -75,6 +79,7 @@ def edit(id):
return { 'form': form }
@mod.route("/add/from/<int:other>")
+@login_required
@templated(".add")
def add_from(other):
exp = ConstExpense() # needed to initialize 'CE.next'
@@ -93,6 +98,7 @@ def add_from(other):
return { 'form': form }
@mod.route("/add/", methods=("GET", "POST"))
+@login_required
@templated()
def add ():
exp = ConstExpense()
@@ -101,6 +107,7 @@ def add ():
if form.validate_on_submit():
form.populate_obj(exp)
+ exp.user = current_user
db.session.add(exp)
db.session.commit()
return redirect(".show", id = exp.id)