From 4b3314a0f41e03e5da70f06334f755d332134c47 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Mon, 1 May 2023 20:33:03 +1000 Subject: [PATCH] Implement pagination for budgets/claims --- sstreasury/jinja2/sstreasury/budget_list.html | 12 ++++++++++ sstreasury/jinja2/sstreasury/claim_list.html | 12 ++++++++++ sstreasury/views.py | 24 ++++++++++++------- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/sstreasury/jinja2/sstreasury/budget_list.html b/sstreasury/jinja2/sstreasury/budget_list.html index 0af2431..c71ab84 100644 --- a/sstreasury/jinja2/sstreasury/budget_list.html +++ b/sstreasury/jinja2/sstreasury/budget_list.html @@ -90,6 +90,18 @@ {{ listbudgets(budgets_closed) }} {% endif %} + +
+ +
{% endblock %} {% block head %} diff --git a/sstreasury/jinja2/sstreasury/claim_list.html b/sstreasury/jinja2/sstreasury/claim_list.html index 6a10e51..8d5c24b 100644 --- a/sstreasury/jinja2/sstreasury/claim_list.html +++ b/sstreasury/jinja2/sstreasury/claim_list.html @@ -90,6 +90,18 @@ {{ listclaims(claims_closed) }} {% endif %} + +
+ +
{% endblock %} {% block head %} diff --git a/sstreasury/views.py b/sstreasury/views.py index 76d4470..9ddd274 100644 --- a/sstreasury/views.py +++ b/sstreasury/views.py @@ -15,12 +15,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied, ValidationError +from django.core.paginator import Paginator from django.core.validators import validate_email - -from django.conf import settings from django.db import transaction from django.db.models import Q from django.http import HttpResponse, JsonResponse @@ -224,12 +224,15 @@ def budget_list(request): budgets_filtered.append(revision) + paginator = Paginator(budgets_filtered, 100) + page = paginator.page(int(request.GET.get('page', '1'))) + # Categorise budgets budgets_action = [] budgets_open = [] budgets_closed = [] - for revision in budgets_filtered: + for revision in page.object_list: state = models.BudgetState(revision.state) group = None @@ -259,7 +262,8 @@ def budget_list(request): return render(request, 'sstreasury/budget_list.html', { 'budgets_action': budgets_action, 'budgets_open': budgets_open, - 'budgets_closed': budgets_closed + 'budgets_closed': budgets_closed, + 'page': page }) @login_required @@ -561,7 +565,7 @@ def budget_action(request, budget, revision): @login_required def claim_list(request): # Filter claims - claims_filter = [] + claims_filtered = [] for claim in models.ReimbursementClaim.objects.all(): if not claim.can_view(request.user): continue @@ -571,14 +575,17 @@ def claim_list(request): if request.GET.get('year', '') != '' and str(claim.time.year) != request.GET.get('year', ''): continue - claims_filter.append(claim) + claims_filtered.append(claim) + + paginator = Paginator(claims_filtered, 100) + page = paginator.page(int(request.GET.get('page', '1'))) # Categorise claims claims_action = [] claims_open = [] claims_closed = [] - for claim in claims_filter: + for claim in page.object_list: state = models.ClaimState(claim.state) group = None @@ -604,7 +611,8 @@ def claim_list(request): return render(request, 'sstreasury/claim_list.html', { 'claims_action': claims_action, 'claims_open': claims_open, - 'claims_closed': claims_closed + 'claims_closed': claims_closed, + 'page': page }) @login_required