Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1788] Refactor case list view #804

Merged
merged 7 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def test_non_digid_user_can_edit_profile(self):
form = edit_page.forms["profile-edit"]
form["first_name"] = "changed_first"
form["last_name"] = "changed_last"
response = form.submit()
form.submit()

user = User.objects.get(id=test_user.id)

Expand Down Expand Up @@ -994,7 +994,7 @@ def test_any_page_for_digid_user_redirect_to_necessary_fields(self):
urls = [
reverse("pages-root"),
reverse("products:category_list"),
reverse("cases:open_cases"),
reverse("cases:index"),
reverse("profile:detail"),
reverse("profile:data"),
reverse("collaborate:plan_list"),
Expand Down
17 changes: 1 addition & 16 deletions src/open_inwoner/cms/cases/tests/test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,7 @@ def test_cases(self, m):
context = self.browser.new_context(storage_state=self.user_login_state)

page = context.new_page()
page.goto(self.live_reverse("cases:open_cases"))

# expected anchors
menu_items = page.get_by_role(
"complementary", name=_("Secundaire paginanavigatie")
).get_by_role("listitem")

expect(
menu_items.get_by_role("link", name=_("Openstaande aanvragen"))
).to_be_visible()
expect(
menu_items.get_by_role("link", name=_("Lopende aanvragen"))
).to_be_visible()
expect(
menu_items.get_by_role("link", name=_("Afgeronde aanvragen"))
).to_be_visible()
page.goto(self.live_reverse("cases:index"))

# case title
case_title = page.get_by_role("link", name=self.zaaktype["omschrijving"])
Expand Down
26 changes: 4 additions & 22 deletions src/open_inwoner/cms/cases/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.urls import path
from django.views.generic import RedirectView

from open_inwoner.accounts.views.contactmoments import (
KlantContactMomentDetailView,
Expand All @@ -11,30 +10,14 @@
CaseDocumentDownloadView,
CaseDocumentUploadFormView,
InnerCaseDetailView,
InnerClosedCaseListView,
InnerOpenCaseListView,
InnerOpenSubmissionListView,
InnerCaseListView,
OuterCaseDetailView,
OuterClosedCaseListView,
OuterOpenCaseListView,
OuterOpenSubmissionListView,
OuterCaseListView,
)

app_name = "cases"

urlpatterns = [
path(
"closed/content/",
InnerClosedCaseListView.as_view(),
name="closed_cases_content",
),
path("closed/", OuterClosedCaseListView.as_view(), name="closed_cases"),
path("forms/", OuterOpenSubmissionListView.as_view(), name="open_submissions"),
path(
"forms/content/",
InnerOpenSubmissionListView.as_view(),
name="open_submissions_content",
),
path(
"contactmomenten/",
KlantContactMomentListView.as_view(),
Expand Down Expand Up @@ -70,7 +53,6 @@
CaseDocumentUploadFormView.as_view(),
name="case_detail_document_form",
),
path("open/", RedirectView.as_view(pattern_name="cases:open_cases"), name="index"),
path("content/", InnerOpenCaseListView.as_view(), name="open_cases_content"),
path("", OuterOpenCaseListView.as_view(), name="open_cases"),
path("content/", InnerCaseListView.as_view(), name="cases_content"),
path("", OuterCaseListView.as_view(), name="index"),
]
8 changes: 1 addition & 7 deletions src/open_inwoner/cms/cases/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from .cases import (
InnerClosedCaseListView,
InnerOpenCaseListView,
OuterClosedCaseListView,
OuterOpenCaseListView,
)
from .cases import InnerCaseListView, OuterCaseListView
from .status import (
CaseContactFormView,
CaseDocumentDownloadView,
CaseDocumentUploadFormView,
InnerCaseDetailView,
OuterCaseDetailView,
)
from .submissions import InnerOpenSubmissionListView, OuterOpenSubmissionListView
129 changes: 42 additions & 87 deletions src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
@@ -1,121 +1,76 @@
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.htmx.mixins import RequiresHtmxMixin
from open_inwoner.openzaak.cases import fetch_cases, preprocess_data
from open_inwoner.openzaak.formapi import fetch_open_submissions
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.types import UniformCase
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import CommonPageMixin

from .mixins import CaseAccessMixin, CaseListMixin, OuterCaseAccessMixin
from .mixins import CaseAccessMixin, CaseLogMixin, OuterCaseAccessMixin


class OuterOpenCaseListView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
):
template_name = "pages/cases/list_outer.html"
class OuterCaseListView(OuterCaseAccessMixin, CommonPageMixin, TemplateView):
"""View on the case list while content is loaded via htmx"""

@cached_property
def crumbs(self):
return [(_("Mijn aanvragen"), reverse("cases:open_cases"))]
template_name = "pages/cases/list_outer.html"

def page_title(self):
return _("Lopende aanvragen")

def get_anchors(self) -> list:
return [
(reverse("cases:open_submissions"), _("Openstaande aanvragen")),
("#cases", _("Lopende aanvragen")),
(reverse("cases:closed_cases"), _("Afgeronde aanvragen")),
]
return _("Mijn aanvragen")

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

# anchors are needed here as well for rendering the mobile ones
context["anchors"] = self.get_anchors()
context["hxget"] = reverse("cases:open_cases_content")
context["hxget"] = reverse("cases:cases_content")
return context


class InnerOpenCaseListView(
RequiresHtmxMixin, CommonPageMixin, CaseAccessMixin, CaseListMixin, TemplateView
class InnerCaseListView(
RequiresHtmxMixin,
CommonPageMixin,
CaseAccessMixin,
CaseLogMixin,
PaginationMixin,
TemplateView,
):
template_name = "pages/cases/list_inner.html"
paginate_by = 9

def page_title(self):
return _("Lopende aanvragen")
return _("Mijn aanvragen")

def get_cases(self):
all_cases = super().get_cases()

cases = [case for case in all_cases if not case.einddatum]
cases.sort(key=lambda case: case.startdatum, reverse=True)
return cases

def get_anchors(self) -> list:
return [
(reverse("cases:open_submissions"), _("Openstaande aanvragen")),
("#cases", _("Lopende aanvragen")),
(reverse("cases:closed_cases"), _("Afgeronde aanvragen")),
]

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["hxget"] = reverse("cases:open_cases_content")
return context


class OuterClosedCaseListView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
):
template_name = "pages/cases/list_outer.html"

@cached_property
def crumbs(self):
return [(_("Mijn aanvragen"), reverse("cases:closed_cases"))]

def page_title(self):
return _("Afgeronde aanvragen")
raw_cases = fetch_cases(self.request.user.bsn)
preprocessed_cases = preprocess_data(raw_cases)
preprocessed_cases.sort(key=lambda case: case.startdatum, reverse=True)
return preprocessed_cases

def get_anchors(self) -> list:
return [
(reverse("cases:open_submissions"), _("Openstaande aanvragen")),
(reverse("cases:open_cases"), _("Lopende aanvragen")),
("#cases", _("Afgeronde aanvragen")),
]
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_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["hxget"] = reverse("cases:closed_cases_content")
context["anchors"] = self.get_anchors()
return context


class InnerClosedCaseListView(
RequiresHtmxMixin, CommonPageMixin, CaseAccessMixin, CaseListMixin, TemplateView
):
template_name = "pages/cases/list_inner.html"
config = OpenZaakConfig.get_solo()

def page_title(self):
return _("Afgeronde aanvragen")
# update ctx with submissions + cases
open_submissions: list[UniformCase] = self.get_submissions()
preprocessed_cases: list[UniformCase] = self.get_cases()
paginator_dict = self.paginate_with_context(
[*open_submissions, *preprocessed_cases]
)
case_dicts = [case.process_data() for case in paginator_dict["object_list"]]
pi-sigma marked this conversation as resolved.
Show resolved Hide resolved

def get_cases(self):
all_cases = super().get_cases()
context["cases"] = case_dicts
context.update(paginator_dict)

cases = [case for case in all_cases if case.einddatum]
cases.sort(key=lambda case: case.einddatum, reverse=True)
return cases
self.log_access_cases(case_dicts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I note this now logs both cases and submissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, submissions are now cases too. I created a Protocol to document this but only added the type hints above (lines 61-62) after Steven's suggestion.


def get_anchors(self) -> list:
return [
(reverse("cases:open_submissions"), _("Openstaande aanvragen")),
(reverse("cases:open_cases"), _("Lopende aanvragen")),
("#cases", _("Afgeronde aanvragen")),
]

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["hxget"] = reverse("cases:closed_cases_content")
# other data
context["hxget"] = reverse("cases:cases_content")
context["title_text"] = config.title_text
return context
Loading
Loading