Skip to content

Commit

Permalink
Fixed issues with paginator, also reverse date ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Mstiekema committed Dec 13, 2023
1 parent 101fcf7 commit 49cf081
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions admin_board_view/templates/transactions.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ <h5>Transaction history</h5>
<tr>
<th>UserID</th>
<th>Date</th>
<th>Transaction sum</th>
<th>Products</th>
<th>Sum</th>
<th>Type</th>
</tr>
</thead>
<tbody>
Expand All @@ -79,12 +79,12 @@ <h5>Transaction history</h5>
<td><a href="/users/{{ top_up.user_id.id }}">{{ top_up.user_id.name }}</a></td>
<td>{{ top_up.date }}</td>
<td>€{{ top_up.transaction_sum }}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 2 %}Credit card{% endif %}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 2 %}Credit card{% elif top_up.type == 3 %}Mollie{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include "pagination_footer.html" with page=sales page_name='top_ups' %}
{% include "pagination_footer.html" with page=top_ups page_name='top_ups' %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion admin_board_view/templates/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h5 class="card-header">Top ups</h5>
<tr>
<td>{{ top_up.date }}</td>
<td>€{{ top_up.transaction_sum }}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 2 %}Credit card{% endif %}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 2 %}Credit card{% elif top_up.type == 3 %}Mollie{% endif %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion admin_board_view/templates/user_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5 class="card-header">Top ups</h5>
<tr>
<td>{{ top_up.date }}</td>
<td>€{{ top_up.transaction_sum }}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 3 %}Mollie{% endif %}</td>
<td>{% if top_up.type == 1 %}Pin{% elif top_up.type == 2 %}Credit card{% elif top_up.type == 3 %}Mollie{% endif %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
11 changes: 8 additions & 3 deletions admin_board_view/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.paginator import Paginator
from django.db.models.query import QuerySet

def create_paginator(data, page, p_len=5):
def create_paginator(data, page_n, p_len=5):
"""
Create paginator for data.
Expand All @@ -9,11 +10,15 @@ def create_paginator(data, page, p_len=5):
page: Page number
p_len: Length of the page, defaults to 5
"""
if isinstance(data, QuerySet):
# Order data, most recent date first
data = data.order_by('date', 'id').reverse()

page = None
paginator = Paginator(data, p_len)
try:
page = paginator.get_page(page)
except Exception:
page = paginator.get_page(page_n)
except Exception as e:
page = paginator.page(1)

return page

0 comments on commit 49cf081

Please sign in to comment.