Implement pagination for budgets/claims

This commit is contained in:
Yingtong Li 2023-05-01 20:33:03 +10:00
parent 1217770900
commit 4b3314a0f4
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 40 additions and 8 deletions

View File

@ -90,6 +90,18 @@
{{ listbudgets(budgets_closed) }} {{ listbudgets(budgets_closed) }}
{% endif %} {% endif %}
<div style="text-align:center;padding-top:1em">
<div class="ui pagination menu">
{% if page.has_previous() %}
<a class="item" href="?page={{ page.previous_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">&lsaquo; Prev</a>
{% endif %}
<a class="active item">Page {{ page.number }} of {{ page.paginator.num_pages }}</a>
{% if page.has_next() %}
<a class="item" href="?page={{ page.next_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">Next &rsaquo;</a>
{% endif %}
</div>
</div>
{% endblock %} {% endblock %}
{% block head %} {% block head %}

View File

@ -90,6 +90,18 @@
{{ listclaims(claims_closed) }} {{ listclaims(claims_closed) }}
{% endif %} {% endif %}
<div style="text-align:center;padding-top:1em">
<div class="ui pagination menu">
{% if page.has_previous() %}
<a class="item" href="?page={{ page.previous_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">&lsaquo; Prev</a>
{% endif %}
<a class="active item">Page {{ page.number }} of {{ page.paginator.num_pages }}</a>
{% if page.has_next() %}
<a class="item" href="?page={{ page.next_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">Next &rsaquo;</a>
{% endif %}
</div>
</div>
{% endblock %} {% endblock %}
{% block head %} {% block head %}

View File

@ -15,12 +15,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.core.paginator import Paginator
from django.core.validators import validate_email from django.core.validators import validate_email
from django.conf import settings
from django.db import transaction from django.db import transaction
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
@ -224,12 +224,15 @@ def budget_list(request):
budgets_filtered.append(revision) budgets_filtered.append(revision)
paginator = Paginator(budgets_filtered, 100)
page = paginator.page(int(request.GET.get('page', '1')))
# Categorise budgets # Categorise budgets
budgets_action = [] budgets_action = []
budgets_open = [] budgets_open = []
budgets_closed = [] budgets_closed = []
for revision in budgets_filtered: for revision in page.object_list:
state = models.BudgetState(revision.state) state = models.BudgetState(revision.state)
group = None group = None
@ -259,7 +262,8 @@ def budget_list(request):
return render(request, 'sstreasury/budget_list.html', { return render(request, 'sstreasury/budget_list.html', {
'budgets_action': budgets_action, 'budgets_action': budgets_action,
'budgets_open': budgets_open, 'budgets_open': budgets_open,
'budgets_closed': budgets_closed 'budgets_closed': budgets_closed,
'page': page
}) })
@login_required @login_required
@ -561,7 +565,7 @@ def budget_action(request, budget, revision):
@login_required @login_required
def claim_list(request): def claim_list(request):
# Filter claims # Filter claims
claims_filter = [] claims_filtered = []
for claim in models.ReimbursementClaim.objects.all(): for claim in models.ReimbursementClaim.objects.all():
if not claim.can_view(request.user): if not claim.can_view(request.user):
continue continue
@ -571,14 +575,17 @@ def claim_list(request):
if request.GET.get('year', '') != '' and str(claim.time.year) != request.GET.get('year', ''): if request.GET.get('year', '') != '' and str(claim.time.year) != request.GET.get('year', ''):
continue 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 # Categorise claims
claims_action = [] claims_action = []
claims_open = [] claims_open = []
claims_closed = [] claims_closed = []
for claim in claims_filter: for claim in page.object_list:
state = models.ClaimState(claim.state) state = models.ClaimState(claim.state)
group = None group = None
@ -604,7 +611,8 @@ def claim_list(request):
return render(request, 'sstreasury/claim_list.html', { return render(request, 'sstreasury/claim_list.html', {
'claims_action': claims_action, 'claims_action': claims_action,
'claims_open': claims_open, 'claims_open': claims_open,
'claims_closed': claims_closed 'claims_closed': claims_closed,
'page': page
}) })
@login_required @login_required