Skip to content

Commit

Permalink
[#2645] Filter cases by status
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Aug 1, 2024
1 parent 743b933 commit 4a30aed
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from furl import furl
from requests import Request
from view_breadcrumbs import BaseBreadcrumbMixin
from zgw_consumers.concurrent import parallel
Expand All @@ -21,6 +22,7 @@
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import CommonPageMixin

from .forms import CaseFilterForm
from .mixins import CaseAccessMixin, CaseLogMixin, OuterCaseAccessMixin

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,13 +79,21 @@ def get_cases_with_api_group(self) -> list[ZaakWithApiGroup]:

def get_cases(self) -> list[Zaak]:
cases_with_api_group = self.get_cases_with_api_group()

return [item.zaak for item in cases_with_api_group]

def get_submissions(self):
subs = fetch_open_submissions(self.request.user.bsn)
subs.sort(key=lambda sub: sub.datum_laatste_wijziging, reverse=True)

return subs

def get_case_status_frequencies(self):
cases = self.get_cases()
case_statuses = [case.status_text for case in cases]

return {status: case_statuses.count(status) for status in case_statuses}


class OuterCaseListView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
Expand All @@ -104,7 +114,12 @@ def page_title(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["hxget"] = reverse("cases:cases_content")
statuses = self.request.GET.getlist("status")

f_url = furl(reverse("cases:cases_content"))
f_url.args["status"] = ",".join(statuses)

context["hxget"] = f_url.url
return context


Expand All @@ -127,10 +142,17 @@ def get_context_data(self, **kwargs):
config = OpenZaakConfig.get_solo()
case_service = CaseService(self.request)

# update ctx with open submissions, cases, + case statuses for filtering
# update ctx with open submissions, cases + form for filtering
open_submissions: list[UniformCase] = case_service.get_submissions()
preprocessed_cases: list[UniformCase] = case_service.get_cases()

statuses = self.request.GET.getlist("status")
# GET.getlist returns [''] if no query params are passed, hence we test by GET.get
if self.request.GET.get("status"):
preprocessed_cases = [
case for case in preprocessed_cases if case.status_text in statuses
]

paginator_dict = self.paginate_with_context(
[*open_submissions, *preprocessed_cases]
)
Expand All @@ -141,6 +163,10 @@ def get_context_data(self, **kwargs):

self.log_access_cases(case_dicts)

context["filter_form"] = CaseFilterForm(
status_freqs=case_service.get_case_status_frequencies()
)

# other data
context["hxget"] = reverse("cases:cases_content")
context["title_text"] = config.title_text
Expand Down
16 changes: 16 additions & 0 deletions src/open_inwoner/cms/cases/views/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import forms


class CaseFilterForm(forms.Form):
def __init__(self, status_freqs: tuple[tuple[str, str]], *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["status"].choices = (
(status, f"{status} ({frequency})")
for status, frequency in status_freqs.items()
)

status = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=dict(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def test_cms_ssd_override_settings(self):

self.assertTrue(benefits_page_is_published())

# import pdbr;pdbr.set_trace()
# check common extension
page = Page.objects.get(publisher_is_draft=False)
extension = page.commonextension
Expand Down
7 changes: 7 additions & 0 deletions src/open_inwoner/templates/pages/cases/list_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ <h1 class="utrecht-heading-1" id="cases">{{ page_title }} ({{ paginator.count }}

<div class="card__grid">

<div>
<form method="GET" >
{{ filter_form }}
<input type='submit' value='submit'>
</form>
</div>

{% render_grid %}
{% if not cases %}
<b>{% trans "U heeft op dit moment nog geen lopende aanvragen." %}</b>
Expand Down

0 comments on commit 4a30aed

Please sign in to comment.