Skip to content

Commit

Permalink
[#890] Refactored to DRY-up fetch_single_information_object() and its…
Browse files Browse the repository at this point in the history
… variant
  • Loading branch information
Bart van der Schoor committed Nov 17, 2022
1 parent 2fe968d commit 521c09f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/open_inwoner/accounts/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
download_document,
fetch_case_information_objects,
fetch_single_information_object,
fetch_single_information_object_uuid,
)
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.statuses import (
Expand Down Expand Up @@ -202,7 +201,7 @@ def get_case_document_files(self, case) -> List[SimpleFile]:
# [case_info.informatieobject for case_info in case_info_objects],
# )
info_objects = [
fetch_single_information_object(case_info.informatieobject)
fetch_single_information_object(url=case_info.informatieobject)
for case_info in case_info_objects
]

Expand Down Expand Up @@ -255,7 +254,7 @@ def handle_no_permission(self):
def get(self, *args, **kwargs):
info_object_uuid = kwargs["object_id"]

info_object = fetch_single_information_object_uuid(info_object_uuid)
info_object = fetch_single_information_object(uuid=info_object_uuid)
if not info_object:
raise Http404

Expand Down
32 changes: 9 additions & 23 deletions src/open_inwoner/openzaak/info_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,22 @@ def fetch_case_information_objects(case_url: str) -> List[ZaakInformatieObject]:
return case_info_objects


def fetch_single_information_object(info_object_url: str) -> Optional[InformatieObject]:
client = build_client("document")

if client is None:
return

try:
response = client.retrieve("enkelvoudiginformatieobject", url=info_object_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return

info_object = factory(InformatieObject, response)

return info_object


def fetch_single_information_object_uuid(
info_object_uuid: str,
def fetch_single_information_object(
*, url: Optional[str] = None, uuid: Optional[str] = None
) -> Optional[InformatieObject]:
if (url and uuid) or (not url and not uuid):
raise ValueError("supply either 'url' or 'uuid' argument")

client = build_client("document")

if client is None:
return

try:
response = client.retrieve("enkelvoudiginformatieobject", uuid=info_object_uuid)
if url:
response = client.retrieve("enkelvoudiginformatieobject", url=url)
else:
response = client.retrieve("enkelvoudiginformatieobject", uuid=uuid)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
Expand Down

0 comments on commit 521c09f

Please sign in to comment.