From 12177709001b55e98a4c469da0384f4dee10d946 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Mon, 1 May 2023 20:18:56 +1000 Subject: [PATCH] Implement basic filtering of claims/budgets --- sstreasury/jinja2/sstreasury/budget_list.html | 37 +++++++++++++++-- sstreasury/jinja2/sstreasury/claim_list.html | 35 +++++++++++++++- sstreasury/views.py | 41 +++++++++++++++---- 3 files changed, 99 insertions(+), 14 deletions(-) diff --git a/sstreasury/jinja2/sstreasury/budget_list.html b/sstreasury/jinja2/sstreasury/budget_list.html index 446679d..0af2431 100644 --- a/sstreasury/jinja2/sstreasury/budget_list.html +++ b/sstreasury/jinja2/sstreasury/budget_list.html @@ -2,7 +2,8 @@ {# Society Self-Service - Copyright © 2018–2020 Yingtong Li (RunasSudo) + Copyright © 2018–2023 Yingtong Li (RunasSudo) + Copyright © 2023 MUMUS Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -28,7 +29,7 @@ Status View - + {% for revision in budgets %} @@ -46,8 +47,30 @@ {% block maincontent %}

Your budgets

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ {% if not budgets_action and not budgets_open and not budgets_closed %} -

You have no budgets to view. To create a budget, click Create new budget.

+

There are no budgets matching the selected criteria. To create a budget, click Create new budget.

{% endif %} {% if budgets_action %} @@ -72,3 +95,11 @@ {% block head %} {{ super() }} {% endblock %} + +{% block script %} + {{ super() }} + + +{% endblock %} diff --git a/sstreasury/jinja2/sstreasury/claim_list.html b/sstreasury/jinja2/sstreasury/claim_list.html index 91195c2..6a10e51 100644 --- a/sstreasury/jinja2/sstreasury/claim_list.html +++ b/sstreasury/jinja2/sstreasury/claim_list.html @@ -2,7 +2,8 @@ {# Society Self-Service - Copyright © 2018–2020 Yingtong Li (RunasSudo) + Copyright © 2018–2023 Yingtong Li (RunasSudo) + Copyright © 2023 MUMUS Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -46,8 +47,30 @@ {% block maincontent %}

Your reimbursement claims

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ {% if not claims_action and not claims_open and not claims_closed %} -

You have no reimbursement claims to view. To create a claim, click Create new claim.

+

There are no reimbursement claims matching the selected criteria. To create a claim, click Create new claim.

{% endif %} {% if claims_action %} @@ -72,3 +95,11 @@ {% block head %} {{ super() }} {% endblock %} + +{% block script %} + {{ super() }} + + +{% endblock %} diff --git a/sstreasury/views.py b/sstreasury/views.py index 811d06c..76d4470 100644 --- a/sstreasury/views.py +++ b/sstreasury/views.py @@ -209,17 +209,29 @@ def index(request): @login_required def budget_list(request): + # Filter budgets + budgets_filtered = [] + for budget in models.Budget.objects.all(): + revision = budget.budgetrevision_set.reverse()[0] + + if not revision.can_view(request.user): + continue + + if request.GET.get('state', 'all') != 'all' and str(revision.state) != request.GET.get('state', 'all'): + continue + if request.GET.get('year', '') != '' and str(revision.time.year) != request.GET.get('year', ''): + continue + + budgets_filtered.append(revision) + + # Categorise budgets budgets_action = [] budgets_open = [] budgets_closed = [] - for budget in models.Budget.objects.all(): - revision = budget.budgetrevision_set.reverse()[0] + for revision in budgets_filtered: state = models.BudgetState(revision.state) - if not revision.can_view(request.user): - continue - group = None if request.user.groups.filter(name='Treasury').exists() and state == models.BudgetState.AWAIT_REVIEW: @@ -548,16 +560,27 @@ def budget_action(request, budget, revision): @login_required def claim_list(request): + # Filter claims + claims_filter = [] + for claim in models.ReimbursementClaim.objects.all(): + if not claim.can_view(request.user): + continue + + if request.GET.get('state', 'all') != 'all' and str(claim.state) != request.GET.get('state', 'all'): + continue + if request.GET.get('year', '') != '' and str(claim.time.year) != request.GET.get('year', ''): + continue + + claims_filter.append(claim) + + # Categorise claims claims_action = [] claims_open = [] claims_closed = [] - for claim in models.ReimbursementClaim.objects.all(): + for claim in claims_filter: state = models.ClaimState(claim.state) - if not claim.can_view(request.user): - continue - group = None if request.user.groups.filter(name='Treasury').exists() and state in [models.ClaimState.AWAIT_REVIEW, models.ClaimState.APPROVED]: