diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2014-01-14 21:36:57 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2014-01-14 21:36:57 +0100 |
commit | c08bf64462490bddddf075be5693807f60e474f1 (patch) | |
tree | 750f921d78f4ce772c7757ed5b6c1bcfb6e1ecc5 /app/views | |
parent | ebe1f3c42ac61ac931dea0c4bdfce9f15d641ade (diff) | |
download | kosten-c08bf64462490bddddf075be5693807f60e474f1.tar.gz kosten-c08bf64462490bddddf075be5693807f60e474f1.tar.bz2 kosten-c08bf64462490bddddf075be5693807f60e474f1.zip |
Default to category name when there is no description given (only on add()!)
Diffstat (limited to 'app/views')
-rw-r--r-- | app/views/expenses.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/views/expenses.py b/app/views/expenses.py index 23cd42e..88c72b6 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -27,15 +27,18 @@ class ExpenseForm(F.Form): description=u'EUR', places=2) - description = F.StringField(u'Beschreibung', F.req) + description = F.StringField(u'Beschreibung') category = F.QuerySelectField(u'Kategorie', get_label='name') - def __init__(self, obj = None): + def __init__(self, obj = None, description_req = True): super(ExpenseForm, self).__init__(obj = obj) self.category.query = Category.of(current_user).order_by(Category.name) + if description_req: + self.description.validators.extend(F.req) + # # Utilities # @@ -108,7 +111,7 @@ def is_last(exp): def show(): """Show this and the last month.""" d = today() - + first, pfirst = calc_month_and_pie(d.year, d.month) if d.month == 1: second, psecond = calc_month_and_pie(d.year - 1, 12) @@ -161,9 +164,12 @@ def edit(id): @templated def add(): """Add a new expense.""" - form = ExpenseForm() + form = ExpenseForm(description_req=False) if form.validate_on_submit(): + if not form.description.data.strip(): + form.description.data = form.category.data.name + exp = SingleExpense() form.populate_obj(exp) |