Skip to content

Commit

Permalink
Paginate the list of bills
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste Jonglez committed Feb 17, 2020
1 parent e4f18f0 commit 248a54c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions ihatemoney/templates/list_bills.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</div>
</div>

{% if bills.count() > 0 %}
{% if bills.total > 0 %}
<div class="clearfix"></div>

<table id="bill_table" class="col table table-striped table-hover table-responsive-sm">
<thead><tr><th>{{ _("When?") }}</th><th>{{ _("Who paid?") }}</<th><th>{{ _("For what?") }}</th><th>{{ _("For whom?") }}</th><th>{{ _("How much?") }}</th><th>{{ _("Actions") }}</th></tr></thead>
<tbody>
{% for bill in bills %}
{% for bill in bills.items %}
<tr owers="{{bill.owers|join(',','id')}}" payer="{{bill.payer.id}}">
<td>
<span data-toggle="tooltip" data-placement="top"
Expand Down Expand Up @@ -133,6 +133,22 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</tbody>
</table>

<div class=pagination>
{{ _("Page:") }}
{%- for page in bills.iter_pages() %}
&nbsp;
{% if page %}
{% if page != bills.page %}
<a href="{{ url_for('main.list_bills', page=page) }}">{{ page }}</a>
{% else %}
<strong>{{ page }}</strong>
{% endif %}
{% else %}
<span class=ellipsis></span>
{% endif %}
{%- endfor %}
</div>

{% else %}
<div class="py-3 d-flex justify-content-center empty-bill">
<div class="card d-inline-flex p-2">
Expand Down
2 changes: 1 addition & 1 deletion ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def list_bills():
if "last_selected_payer" in session:
bill_form.payer.data = session["last_selected_payer"]
# Preload the "owers" relationship for all bills
bills = g.project.get_bills().options(orm.subqueryload(Bill.owers))
bills = g.project.get_bills().options(orm.subqueryload(Bill.owers)).paginate(per_page=100, error_out=True)

return render_template(
"list_bills.html",
Expand Down

0 comments on commit 248a54c

Please sign in to comment.