File size: 1,593 Bytes
b4f2238 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """Case admin export bridge helpers."""
from __future__ import annotations
from typing import TYPE_CHECKING, Callable
if TYPE_CHECKING:
from apps.cases.models import Case
_CASE_ADMIN_EXPORT_PREFETCHES: tuple[str, ...] = (
"parties__client__identity_docs",
"parties__client__property_clues__attachments",
"assignments__lawyer",
"supervising_authorities",
"case_numbers",
"chats",
"logs__actor",
"logs__attachments",
)
_CASE_ADMIN_FILE_PREFETCHES: tuple[str, ...] = (
"parties__client__identity_docs",
"parties__client__property_clues__attachments",
"logs__attachments",
)
def get_case_admin_export_prefetches() -> tuple[str, ...]:
"""Return case-side prefetch paths needed by CaseAdmin export."""
return _CASE_ADMIN_EXPORT_PREFETCHES
def get_case_admin_file_prefetches() -> tuple[str, ...]:
"""Return case-side prefetch paths needed by CaseAdmin file export."""
return _CASE_ADMIN_FILE_PREFETCHES
def collect_case_file_paths_for_export(
case: Case,
add_path: Callable[[str], None],
) -> None:
"""Collect case-side file paths for admin export."""
for party in case.parties.all():
for identity_doc in party.client.identity_docs.all():
add_path(identity_doc.file_path)
for clue in party.client.property_clues.all():
for attachment in clue.attachments.all():
add_path(attachment.file_path)
for log in case.logs.all():
for attachment in log.attachments.all():
if attachment.file:
add_path(attachment.file.name)
|