summaryrefslogtreecommitdiff
path: root/app/views
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2014-12-15 00:44:30 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2014-12-15 00:44:30 +0100
commiteb1886ce939e4268bf0aa43c0de85515cf2a6604 (patch)
tree3e76f504669bd7279e71e877a3714f32fba605b0 /app/views
parent887be010bf1aa13580a36e6829b5690e03abfe9a (diff)
downloadkosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.tar.gz
kosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.tar.bz2
kosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.zip
Search function
Diffstat (limited to 'app/views')
-rw-r--r--app/views/expenses.py24
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 }