summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-01-15 17:03:44 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-01-15 17:03:44 +0100
commitbeb62795be1b397887cd9e69f84211e7f0509201 (patch)
treee962f3ec9d8d629132593e4b3545b9682a066c02
parent9d4586a425c182af61c2ef7d39f397124f680b9c (diff)
downloadbank-beb62795be1b397887cd9e69f84211e7f0509201.tar.gz
bank-beb62795be1b397887cd9e69f84211e7f0509201.tar.bz2
bank-beb62795be1b397887cd9e69f84211e7f0509201.zip
fixing the back-and-forth arrows to navigate multiple
pages /public-history results.
-rw-r--r--talerbank/app/static/bank.css12
-rw-r--r--talerbank/app/templates/public_accounts.html78
-rw-r--r--talerbank/app/views.py8
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 @@
</ul>
</div>
- {% if selected_account.history %}
- <table class="pure-table pure-table-striped">
- <thead>
- <th>Date</th>
- <th>Amount</th>
- <th>Counterpart</th>
- <th>Subject</th>
- </thead>
- <tbody>
- {% for entry in selected_account.history %}
- <tr>
- <td>{{entry.date}}</td>
- <td>
- {{ entry.sign }} {{ entry.amount }}
- </td>
- <td>{% if entry.counterpart_username %} {{ entry.counterpart_username }} {% endif %} (account #{{ entry.counterpart }})</td>
- <td {% if entry.cancelled %} class="cancelled" {% endif %}>
- {{ entry.subject }}
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- {% for pagej in pages %}
- <a href="{{ url("public-accounts", name=selected_account.name, page=pagej) }}">{{ pagej }}</a>
- {% endfor %}
- {% else %}
- <p>No history for account #{{ selected_account.number }} ({{ selected_account.name}}) yet</p>
- {% endif %}
+ <div class="results">
+ {% if selected_account.history %}
+ <table class="pure-table pure-table-striped">
+ <thead>
+ <th>Date</th>
+ <th>Amount</th>
+ <th>Counterpart</th>
+ <th>Subject</th>
+ </thead>
+ <tbody>
+ {% for entry in selected_account.history %}
+ <tr>
+ <td>{{entry.date}}</td>
+ <td>
+ {{ entry.sign }} {{ entry.amount }}
+ </td>
+ <td>{% if entry.counterpart_username %} {{ entry.counterpart_username }} {% endif %} (account #{{ entry.counterpart }})</td>
+ <td {% if entry.cancelled %} class="cancelled" {% endif %}>
+ {{ entry.subject }}
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ <div class="pages-list">
+ {% if back %}
+ <a
+ class="page-number"
+ href="{{ url("public-accounts", name=selected_account.name, page=back) }}">&lsaquo;...</a>
+ {% endif %}
+ {% for pagej in pages %}
+ <a
+ {% if pagej == current_page%}
+ class="current-page-number"
+ {% else %}
+ class="page-number"
+ {% endif %}
+ href="{{ url("public-accounts", name=selected_account.name, page=pagej) }}">{{ pagej }}</a>
+ {% endfor %}
+ {% if forth %}
+ <a
+ class="page-number"
+ href="{{ url("public-accounts", name=selected_account.name, page=forth) }}">...&rsaquo;</a>
+ {% endif %}
+ </div>
+ {% else %}
+ <p>No history for account #{{ selected_account.number }} ({{ selected_account.name}}) yet</p>
+ {% endif %}
+ </div>
</article>
</section>
{% 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,