Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate the list of bills #480

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ihatemoney/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ footer .footer-left {
margin-top: 30px;
}

#previous-page {
margin-top: 30px;
}

#next-page {
margin-top: 30px;
padding-left: 2em;
}

/* Avoid text color flickering when it loose focus as the modal appears */
.btn-primary[data-toggle="modal"] {
color: #fff;
Expand Down
28 changes: 26 additions & 2 deletions ihatemoney/templates/list_bills.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</div>
</div>

{% if bills.count() > 0 %}
{% if bills.pages > 1 %}
<span id="previous-page" class="float-left">
<a class="btn btn-outline-secondary float-left {% if bills.page == 1 %}disabled{% endif %}" href="{{ url_for('main.list_bills', page=bills.prev_num) }}">&laquo; {{ _("Newer bills") }}</a>
</span>

<span id="next-page" class="float-left">
<a class="btn btn-outline-secondary float-left {% if bills.page == bills.pages %}disabled{% endif %}" href="{{ url_for('main.list_bills', page=bills.next_num) }}">{{ _("Older bills") }} &raquo;</a>
</span>
{% endif %}

{% 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 +143,20 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</tbody>
</table>

{% if bills.pages > 1 %}
<ul class="pagination">
<li class="page-item {% if bills.page == 1 %}disabled{% endif %}"><a class="page-link" href="{{ url_for('main.list_bills', page=bills.prev_num) }}">&laquo; Newer bills</a></li>
{%- for page in bills.iter_pages() %}
{% if page %}
<li class="page-item {% if page == bills.page %}active{% endif %}"><a class="page-link" href="{{ url_for('main.list_bills', page=page) }}">{{ page }}</a></li>
{% else %}
<li class="page-item disabled"><span class="ellipsis page-link"></span></li>
{% endif %}
{%- endfor %}
<li class="page-item {% if bills.page == bills.pages %}disabled{% endif %}"><a class="page-link" href="{{ url_for('main.list_bills', page=bills.next_num) }}">Older bills &raquo;</a></li>
</ul>
{% endif %}

{% else %}
<div class="py-3 d-flex justify-content-center empty-bill">
<div class="card d-inline-flex p-2">
Expand Down
6 changes: 5 additions & 1 deletion ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,11 @@ 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