From beb62795be1b397887cd9e69f84211e7f0509201 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Mon, 15 Jan 2018 17:03:44 +0100 Subject: fixing the back-and-forth arrows to navigate multiple pages /public-history results. --- talerbank/app/static/bank.css | 12 +++++ talerbank/app/templates/public_accounts.html | 78 +++++++++++++++++----------- talerbank/app/views.py | 8 ++- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/talerbank/app/static/bank.css b/talerbank/app/static/bank.css index 20e7586..4c16e94 100644 --- a/talerbank/app/static/bank.css +++ b/talerbank/app/static/bank.css @@ -3,6 +3,18 @@ h1.nav { display: inline-block; } +div.pages-list { + margin-top: 15px; +} + +a.page-number { + color: blue; +} + +a.current-page-number { + color: inherit; +} + a.pure-button { position: absolute; right: 20px; diff --git a/talerbank/app/templates/public_accounts.html b/talerbank/app/templates/public_accounts.html index edbfdbc..3ebe6ad 100644 --- a/talerbank/app/templates/public_accounts.html +++ b/talerbank/app/templates/public_accounts.html @@ -55,35 +55,55 @@ - {% if selected_account.history %} - - - - - - - - - {% for entry in selected_account.history %} - - - - - - - {% endfor %} - -
DateAmountCounterpartSubject
{{entry.date}} - {{ entry.sign }} {{ entry.amount }} - {% if entry.counterpart_username %} {{ entry.counterpart_username }} {% endif %} (account #{{ entry.counterpart }}) - {{ entry.subject }} -
- {% for pagej in pages %} - {{ pagej }} - {% endfor %} - {% else %} -

No history for account #{{ selected_account.number }} ({{ selected_account.name}}) yet

- {% endif %} +
+ {% if selected_account.history %} + + + + + + + + + {% for entry in selected_account.history %} + + + + + + + {% endfor %} + +
DateAmountCounterpartSubject
{{entry.date}} + {{ entry.sign }} {{ entry.amount }} + {% if entry.counterpart_username %} {{ entry.counterpart_username }} {% endif %} (account #{{ entry.counterpart }}) + {{ entry.subject }} +
+
+ {% if back %} + ‹... + {% endif %} + {% for pagej in pages %} + {{ pagej }} + {% endfor %} + {% if forth %} + ...› + {% endif %} +
+ {% else %} +

No history for account #{{ selected_account.number }} ({{ selected_account.name}}) yet

+ {% endif %} +
{% endblock content %} diff --git a/talerbank/app/views.py b/talerbank/app/views.py index 81eeb6d..fa6efa4 100644 --- a/talerbank/app/views.py +++ b/talerbank/app/views.py @@ -18,6 +18,7 @@ # @author Florian Dold from functools import wraps +import math import json import logging import hashlib @@ -385,9 +386,12 @@ def serve_public_accounts(request, name=None, page=None): num_pages = request.session["public_history_account"][0] / DELTA pages = list( - range(max(1, page - 3), min(page + 4, int(num_pages)))) - print(pages) + range(max(1, page - 3), + min(page + 4, math.ceil(num_pages)))) context = dict( + current_page=page, + back = page - 1 if pages[0] > 1 else None, + forth = page + 1 if pages[-1] < num_pages else None, public_accounts=public_accounts, selected_account=dict( fail_message=fail_message, -- cgit v1.2.3