Skip to content

Commit

Permalink
[#1788] Process PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Oct 25, 2023
1 parent 081b028 commit a086751
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 117 deletions.
2 changes: 0 additions & 2 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 Down Expand Up @@ -54,7 +53,6 @@
CaseDocumentUploadFormView.as_view(),
name="case_detail_document_form",
),
path("open/", RedirectView.as_view(), name="redirect"),
path("content/", InnerCaseListView.as_view(), name="cases_content"),
path("", OuterCaseListView.as_view(), name="index"),
]
18 changes: 5 additions & 13 deletions src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
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, CaseLogMixin, OuterCaseAccessMixin


class OuterCaseListView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
):
class OuterCaseListView(OuterCaseAccessMixin, CommonPageMixin, TemplateView):
"""View on case list while being loaded"""

template_name = "pages/cases/list_outer.html"

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

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

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

Expand Down Expand Up @@ -67,9 +59,9 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
config = OpenZaakConfig.get_solo()

# update ctx with cases + submissions
preprocessed_cases = self.get_cases()
open_submissions = self.get_submissions()
# 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]
)
Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/cms/cases/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def log_access_cases(self, cases: list[dict]):
"""
Log access to cases on the list view (create single log for all cases)
"""
case_ids = (case["identificatie"] for case in cases)
case_ids = (case["identification"] for case in cases)

self.log_user_action(
self.request.user,
_("Zaaken bekeken: {cases}").format(cases=", ".join(case_ids)),
_("Zaken bekeken: {cases}").format(cases=", ".join(case_ids)),
)

def log_access_case_detail(self, case: UniformCase):
Expand All @@ -33,7 +33,7 @@ def log_access_case_detail(self, case: UniformCase):
"""
self.log_user_action(
self.request.user,
_("Zaak bekeken: {case}").format(case=case.identificatie),
_("Zaak bekeken: {case}").format(case=case.identification),
)


Expand Down
4 changes: 1 addition & 3 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def get_context_data(self, **kwargs):

context["case"] = {
"id": str(self.case.uuid),
"identification": self.case.format_zaak_identificatie(
self.case.identificatie, config
),
"identification": self.case.identification,
"initiator": self.get_initiator_display(self.case),
"result": self.get_result_display(self.case),
"start_date": self.case.startdatum,
Expand Down
28 changes: 16 additions & 12 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Zaak(ZGWModel):
# zaakgeometrie: dict

@staticmethod
def _reformat_esuite_zaak_identificatie(identificatie: str):
def _reformat_esuite_zaak_identificatie(identificatie: str) -> str:
"""
0014ESUITE66392022 -> 6639-2022
Expand All @@ -52,28 +52,31 @@ def _reformat_esuite_zaak_identificatie(identificatie: str):
year = m.group("year")
return f"{num}-{year}"

def format_zaak_identificatie(
def _format_zaak_identificatie(
self,
identificatie: str,
zaak_config: "OpenZaakConfig",
):
) -> str:
from open_inwoner.openzaak.models import OpenZaakConfig

zaak_config = OpenZaakConfig.get_solo()

if zaak_config.reformat_esuite_zaak_identificatie:
return self._reformat_esuite_zaak_identificatie(self.identificatie)
return identificatie
return self.identificatie

def process_data(self):
@property
def identification(self) -> str:
return self._format_zaak_identificatie()

def process_data(self) -> dict:
"""
Prepare data for template
"""
from open_inwoner.openzaak.models import OpenZaakConfig, StatusTranslation
from open_inwoner.openzaak.models import StatusTranslation

zaak_config = OpenZaakConfig.get_solo()
status_translate = StatusTranslation.objects.get_lookup()

return {
"identificatie": self.format_zaak_identificatie(
self.identificatie, zaak_config
),
"identification": self.identification,
"uuid": str(self.uuid),
"start_date": self.startdatum,
"end_date": getattr(self, "einddatum", None),
Expand All @@ -82,6 +85,7 @@ def process_data(self):
self, "status.statustype.omschrijving", default=""
),
"statustype_config": getattr(self, "statustype_config", None),
"case_type": "Zaak",
}


Expand Down
3 changes: 1 addition & 2 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ def resolve_zaak_type(cases: list[Zaak]) -> None:

# fetch unique case types
for case_type_url in case_types_set:
# todo parallel
case_types[case_type_url] = fetch_single_case_type(case_type_url)

# set resolved case types
Expand All @@ -321,7 +320,7 @@ def add_status_type_config(case: Zaak):
"""
Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case
Note: must be called before the call to `resolve_status_type`, since we need
Note: must be called before the call to `resolve_status_type` since we need
the unresolved status type url here
"""
case_statustype_url = case.status.statustype
Expand Down
20 changes: 3 additions & 17 deletions src/open_inwoner/openzaak/catalog.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
import logging
from typing import List, Optional, Union
from uuid import UUID
from typing import List, Optional

from django.conf import settings

from requests import RequestException
from zds_client import ClientError, get_operation_url
from zds_client import ClientError
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.catalogi import Catalogus
from zgw_consumers.service import get_paginated_results

from ..utils.decorators import cache as cache_result
from .api_models import InformatieObjectType, ResultaatType, StatusType, ZaakType
from .clients import build_client
from .utils import get_retrieve_resource_by_uuid_url

logger = logging.getLogger(__name__)


def get_retrieve_resource_by_uuid_url(
client, resource: str, uuid: Union[str, UUID]
) -> str:
op_suffix = client.operation_suffix_mapping["retrieve"]
operation_id = f"{resource}{op_suffix}"
path_kwargs = {
"uuid": uuid,
}
url = get_operation_url(
client.schema, operation_id, base_url=client.base_url, **path_kwargs
)
return url


# not cached because only used by tools,
# and because caching (stale) listings can break lookups
def fetch_status_types_no_cache(case_type_url: str) -> List[StatusType]:
Expand Down
10 changes: 7 additions & 3 deletions src/open_inwoner/openzaak/formapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ class OpenSubmission(Model):
eind_datum_geldigheid: Optional[datetime] = None

@property
def identificatie(self):
def identification(self) -> str:
return f"{self.naam}: {self.uuid}"

def process_data(self):
def process_data(self) -> dict:
"""
Prepare data for template
"""
return {
"identification": self.identification,
"url": self.url,
"uuid": self.uuid,
"naam": self.naam,
"identificatie": self.identificatie,
"vervolg_link": self.vervolg_link,
"datum_laatste_wijziging": self.datum_laatste_wijziging,
"eind_datum_geldigheid": self.eind_datum_geldigheid or "Geen",
"case_type": "OpenSubmission",
}


Expand Down
4 changes: 1 addition & 3 deletions src/open_inwoner/openzaak/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ def send_case_update_email(user: User, case: Zaak):
"""
send the actual mail
"""
config = OpenZaakConfig.get_solo()

case_detail_url = build_absolute_url(
reverse("cases:case_detail", kwargs={"object_id": str(case.uuid)})
)

template = find_template("case_notification")
context = {
"identification": case.format_zaak_identificatie(case.identificatie, config),
"identification": case.identification,
"type_description": case.zaaktype.omschrijving,
"start_date": case.startdatum,
"case_link": case_detail_url,
Expand Down
9 changes: 4 additions & 5 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
from ...utils.tests.helpers import AssertRedirectsMixin
from ..api_models import Status, StatusType
from ..models import OpenZaakConfig

# TODO delete
# from ..utils import format_zaak_identificatie
from .factories import CatalogusConfigFactory, ServiceFactory
from .shared import CATALOGI_ROOT, DOCUMENTEN_ROOT, ZAKEN_ROOT

Expand Down Expand Up @@ -414,11 +411,13 @@ def test_page_reformats_zaak_identificatie(self, m):
self._setUpMocks(m)

with patch(
"open_inwoner.openzaak.api_models.Zaak.format_zaak_identificatie",
"open_inwoner.openzaak.api_models.Zaak._format_zaak_identificatie",
) as spy_format:
self.app.get(self.case_detail_url, user=self.user)

spy_format.assert_called_once()
# _format_zaak_identificatie is called twice on requesting DetailVew:
# once for the log, once for adding case to context
spy_format.assert_called

def test_page_translates_statuses(self, m):
st1 = StatusTranslationFactory(
Expand Down
Loading

0 comments on commit a086751

Please sign in to comment.