diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2014-12-15 00:44:30 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2014-12-15 00:44:30 +0100 |
commit | eb1886ce939e4268bf0aa43c0de85515cf2a6604 (patch) | |
tree | 3e76f504669bd7279e71e877a3714f32fba605b0 | |
parent | 887be010bf1aa13580a36e6829b5690e03abfe9a (diff) | |
download | kosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.tar.gz kosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.tar.bz2 kosten-eb1886ce939e4268bf0aa43c0de85515cf2a6604.zip |
Search function
Diffstat (limited to '')
-rw-r--r-- | app/views/expenses.py | 24 | ||||
-rw-r--r-- | static/css/style.css | 33 | ||||
-rw-r--r-- | static/images/lupe.png | bin | 0 -> 475 bytes | |||
-rw-r--r-- | static/js/kosten.js | 14 | ||||
-rw-r--r-- | static/js/kosten.ls | 12 | ||||
-rw-r--r-- | templates/expenses/search.jinja | 25 | ||||
-rw-r--r-- | templates/layout.jinja | 9 |
7 files changed, 117 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 } diff --git a/static/css/style.css b/static/css/style.css index da928b4..5b232b3 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -170,6 +170,39 @@ ul.arrow { color: #000000; } +li.search { + display: block; + float: left; + cursor: pointer; + position: relative; +} + +img.search { + padding: 9px 10px; +} + +form.search { + position: relative; +} + +input.search { + position: absolute; + top: -10px; + left: -30px; + width: 80px; + overflow: hidden; +} + +input.search-submit { + position: absolute; + top: -20px; + z-index: -1; + color: transparent; + border: none; + outline: none; + opacity: 0; +} + /** LOGO */ #logo { diff --git a/static/images/lupe.png b/static/images/lupe.png Binary files differnew file mode 100644 index 0000000..55a6e2f --- /dev/null +++ b/static/images/lupe.png diff --git a/static/js/kosten.js b/static/js/kosten.js index 41bf30f..e2fa06a 100644 --- a/static/js/kosten.js +++ b/static/js/kosten.js @@ -24,6 +24,20 @@ } }); }; + $(function(){ + $('form.search').hide(); + $('li.search').click(function(){ + var x$; + x$ = $('form.search'); + x$.toggle(); + if (x$.is(':visible')) { + $('input.search').focus(); + } + }); + $('input.search').focusout(function(){ + $('form.search').hide(); + }); + }); out$.addJS = addJS = jq(function(){ $('input[name=date]').datepicker({ dateFormat: 'dd.mm.yy', diff --git a/static/js/kosten.ls b/static/js/kosten.ls index 5362fb3..e3a60d2 100644 --- a/static/js/kosten.ls +++ b/static/js/kosten.ls @@ -20,6 +20,18 @@ set-lang = !-> range-selector-to: \bis range-selector-zoom: null +# The Search Stuff +$ !-> + $ \form.search .hide! + + $ \li.search .click !-> + $ \form.search + ..toggle! + $ \input.search .focus! if .. .is \:visible + + $ \input.search .focusout !-> + $ \form.search .hide! + # Add export addJS = jq !-> $ 'input[name=date]' .datepicker do diff --git a/templates/expenses/search.jinja b/templates/expenses/search.jinja new file mode 100644 index 0000000..5cd294b --- /dev/null +++ b/templates/expenses/search.jinja @@ -0,0 +1,25 @@ +{% extends "layout.jinja" %} + +{% block heading %} + Suchergebnisse +{% endblock %} + +{% block content %} + + {% set year = None %} + + {% for exp in exps %} + {% if exp.year != year %} + {% if year != None %}</ul>{% endif %} + {% set year = exp.year %} + <h2>{{ year }}</h2> + <ul> + {% endif %} + + <li> + <a href="{{ url_for(".edit", id = exp.id) }}">{{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur }}</a> + </li> + + {% endfor %} + +{% endblock %} diff --git a/templates/layout.jinja b/templates/layout.jinja index b71b6ec..5cb03b8 100644 --- a/templates/layout.jinja +++ b/templates/layout.jinja @@ -27,6 +27,15 @@ {% for uri, page in menu %} <li class="menu-item"><a href="{{ url_for(uri) }}">{{page}}</a></li> {% endfor %} + {% if current_user.is_authenticated() %} + <li class="search"> + <img class="search" src="{{ "images/lupe.png" | static_url }}" alt="Search"> + <form class="search" method="post" action="{{ url_for("expenses.search") }}"> + <input type="search" value="" name="search" class="search"> + <input type="submit" value="" class="search-submit"> + </form> + </li> + {% endif %} </ul> {% endblock %} </div> |