summaryrefslogtreecommitdiff
path: root/app/views/consts.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/consts.py')
-rw-r--r--app/views/consts.py57
1 files changed, 35 insertions, 22 deletions
diff --git a/app/views/consts.py b/app/views/consts.py
index 97afad1..4b5ea68 100644
--- a/app/views/consts.py
+++ b/app/views/consts.py
@@ -7,14 +7,15 @@ from . import Blueprint, flash, db, \
from ..model import Category, ConstExpense
from .. import forms as F
-import datetime
from sqlalchemy import sql
from functools import partial
-assert_authorisation = partial(assert_authorisation, ConstExpense.get)
-
mod = Blueprint('consts', __name__)
+assert_authorisation = partial(assert_authorisation, ConstExpense.get)
+#
+# Form
+#
class ConstForm(F.Form):
start = F.DateField(u'Beginn', F.req,
format='%m.%Y',
@@ -43,7 +44,7 @@ class ConstForm(F.Form):
def __init__(self, cur=None, obj=None):
obj = cur if obj is None else obj
- super(F.Form, self).__init__(obj=obj)
+ super(ConstForm, self).__init__(obj=obj)
self.category.query = Category.of(current_user).order_by(Category.name)
# init prev_list
@@ -57,10 +58,14 @@ class ConstForm(F.Form):
self.prev.query = CE.of(current_user).filter(filter).order_by(CE.description)
+#
+# Views
+#
@mod.route('/')
@login_required
@templated
def list ():
+ """List all constant expenses."""
d = today()
expenses = ConstExpense.of(current_user).order_by(ConstExpense.description).all()
@@ -80,18 +85,22 @@ def list ():
return { 'current': current, 'old': old, 'future': future }
+
@mod.route('/<int:id>')
@login_required
@assert_authorisation('id')
@templated
def show(id):
+ """Show a specific constant expense."""
return { 'exp': ConstExpense.get(id) }
+
@mod.route('/edit/<int:id>', methods=('GET', 'POST'))
@login_required
@assert_authorisation('id')
@templated
def edit(id):
+ """Edit a specific constant expense. This includes deletion."""
exp = ConstExpense.get(id)
form = ConstForm(exp)
@@ -109,11 +118,33 @@ def edit(id):
return { 'form': form }
+
+@mod.route('/add/', methods=('GET', 'POST'))
+@login_required
+@templated
+def add():
+ """Add a new constant expense."""
+ exp = ConstExpense()
+
+ form = ConstForm()
+
+ if form.validate_on_submit():
+ form.populate_obj(exp)
+ exp.user = current_user
+ db.session.add(exp)
+ db.session.commit()
+ flash(u"Eintrag hinzugefügt.")
+ return redirect('.show', id = exp.id)
+
+ return { 'form': form }
+
+
@mod.route('/add/from/<int:other>')
@login_required
@assert_authorisation('other')
@templated('.add')
def add_from(other):
+ """Copy `other` and create a new expense based on it."""
exp = ConstExpense() # needed to initialize 'CE.next'
other = ConstExpense.get(other)
@@ -128,21 +159,3 @@ def add_from(other):
if not other.next: form.prev.data = other
return { 'form': form }
-
-@mod.route('/add/', methods=('GET', 'POST'))
-@login_required
-@templated
-def add ():
- exp = ConstExpense()
-
- form = ConstForm()
-
- if form.validate_on_submit():
- form.populate_obj(exp)
- exp.user = current_user
- db.session.add(exp)
- db.session.commit()
- flash(u"Eintrag hinzugefügt.")
- return redirect('.show', id = exp.id)
-
- return { 'form': form }