diff options
Diffstat (limited to 'app/views/expenses.py')
-rw-r--r-- | app/views/expenses.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/views/expenses.py b/app/views/expenses.py index 88c72b6..2a5bd32 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -183,3 +183,27 @@ def add(): return redirect('.add') return { 'form': form } + +@mod.route('/search', methods=('POST', 'GET')) +@login_required +@templated +def search(): + try: + query = request.form['search'].strip() + except KeyError: + flash(u"Ungültige Suchanfrage") + return redirect('index') + + if not query: + flash(u"Leere Suche") + return redirect('index') + + exps = SingleExpense.of(current_user).filter(SingleExpense.description.ilike(query))\ + .order_by(SingleExpense.year.desc(), SingleExpense.month, SingleExpense.day, SingleExpense.description)\ + .all() + + if not exps: + flash(u"Keine Ergebnisse") + return redirect('index') + + return { 'exps': exps } |