From b89b9fe94433bee2a71fcc585d9b3a2b51ac3dbe Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 8 Jul 2026 09:07:25 +0000 Subject: [PATCH] =?UTF-8?q?Name=20the=20packaged=20file=20by=20Document=20?= =?UTF-8?q?Type=20with=20the=20original=20extension=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- domain/bulk_document_download/package_plan.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/domain/bulk_document_download/package_plan.py b/domain/bulk_document_download/package_plan.py index bcd122aad..535928596 100644 --- a/domain/bulk_document_download/package_plan.py +++ b/domain/bulk_document_download/package_plan.py @@ -8,6 +8,7 @@ orchestrator does the S3/DB work; this module only lays out the archive. from __future__ import annotations +import posixpath from dataclasses import dataclass from datetime import datetime from typing import Optional, Sequence @@ -57,6 +58,14 @@ class DownloadPackagePlan: skipped: tuple[SkippedDocument, ...] +def _extension_of(s3_key: str) -> str: + """The file extension of an S3 key (``.pdf``, ``.zip``, …), empty when the + key's basename has none. Used to keep the packaged file openable while + naming it by Document Type.""" + _root, ext = posixpath.splitext(posixpath.basename(s3_key)) + return ext + + def plan_download_package( documents: Sequence[ResolvedDocument], ) -> DownloadPackagePlan: @@ -83,7 +92,7 @@ def plan_download_package( entries: list[PackageEntry] = [ PackageEntry( zip_path=f"{document.address} ({document.landlord_property_id})/" - f"{document.document_type}", + f"{document.document_type}{_extension_of(document.s3_key)}", s3_bucket=document.s3_bucket, s3_key=document.s3_key, )