summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-07-24 09:27:06 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-07-24 09:27:06 +0200
commit82e92d5c2825564655f1b8f0c2c779ab82856ba3 (patch)
tree3a2b83e28340fa6fa9aa22b9886a22a1fe806d24
parent6600ae0674bc685c4756a040b4db47e927f2e15e (diff)
downloadkosten-82e92d5c2825564655f1b8f0c2c779ab82856ba3.tar.gz
kosten-82e92d5c2825564655f1b8f0c2c779ab82856ba3.tar.bz2
kosten-82e92d5c2825564655f1b8f0c2c779ab82856ba3.zip
Fix handling of prefilling the description field on adding a new expense.
-rw-r--r--kosten/app/views/expenses.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/kosten/app/views/expenses.py b/kosten/app/views/expenses.py
index 90c8ffd..0473cda 100644
--- a/kosten/app/views/expenses.py
+++ b/kosten/app/views/expenses.py
@@ -26,19 +26,16 @@ class ExpenseForm(F.Form):
description='EUR',
places=2)
- description = F.StringField('Beschreibung')
+ description = F.StringField('Beschreibung', F.req)
category = F.QuerySelectField('Kategorie',
get_label='name',
get_pk=lambda c: c.id)
- def __init__(self, obj = None, description_req = True):
+ def __init__(self, obj = None):
super().__init__(obj = obj)
self.category.query = Category.of(current_user).order_by(Category.name)
- if description_req:
- self.description.validators.extend(F.req)
-
#
# Utilities
#
@@ -176,15 +173,15 @@ def edit(id):
@templated
def add():
"""Add a new expense."""
- form = ExpenseForm(description_req=False)
+ form = ExpenseForm()
if request.method == 'GET' and 'date' in request.args:
form.date.data = parse_date(request.args['date'])
- if form.validate_on_submit():
- if not form.description.data.strip():
- form.description.data = form.category.data.name
+ if form.is_submitted() and not form.description.data.strip():
+ form.description.data = form.category.data.name
+ if form.validate_on_submit():
exp = SingleExpense()
form.populate_obj(exp)