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 2, 2024
1 parent fce5da5 commit db3c7bf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
47 changes: 41 additions & 6 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 @@ -50,7 +52,7 @@ def get_cases_for_api_group(self, group: ZGWApiGroupConfig):
preprocessed_cases = preprocess_data(raw_cases, group)
return preprocessed_cases

def get_cases_with_api_group(self) -> list[ZaakWithApiGroup]:
def get_cases(self) -> list[ZaakWithApiGroup]:
all_api_groups = list(ZGWApiGroupConfig.objects.all())

with parallel() as executor:
Expand All @@ -75,15 +77,28 @@ def get_cases_with_api_group(self) -> list[ZaakWithApiGroup]:

return cases_with_api_group

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_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()
submissions = self.get_submissions()

case_statuses = [case.zaak.status_text for case in cases]

# add static text for open submissions
case_statuses += ["Openstaande aanvraag" for submission in submissions]

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


class OuterCaseListView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
Expand All @@ -104,7 +119,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 +147,20 @@ 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"):
open_submissions = (
open_submissions if "Openstaande aanvraag" in statuses else []
)
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 +171,11 @@ def get_context_data(self, **kwargs):

self.log_access_cases(case_dicts)

context["form"] = CaseFilterForm(
status_freqs=case_service.get_case_status_frequencies(),
status_initial=statuses,
)

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


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

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

status = forms.MultipleChoiceField(
label=_("Filter by status"),
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
9 changes: 9 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,15 @@ <h1 class="utrecht-heading-1" id="cases">{{ page_title }} ({{ paginator.count }}

<div class="card__grid">

<div>
<form method="GET">
<table>
{{ form }}
</table>
<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 db3c7bf

Please sign in to comment.