Download apps/contracts/services/contract/admin/contract_admin_document_service.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/contracts/services/contract/admin/contract_admin_document_service.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/contracts/services/contract/admin/contract_admin_document_service.py
-
curl -L -o contract_admin_document_service.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/contracts/services/contract/admin/contract_admin_document_service.py
1.96 kB
| """Business logic services.""" | |
| from __future__ import annotations | |
| from typing import Any | |
| from apps.core.exceptions import NotFoundError, ValidationException | |
| from ..wiring import ( | |
| get_contract_folder_binding_service, | |
| get_contract_generation_service, | |
| get_supplementary_agreement_generation_service, | |
| ) | |
| class ContractAdminDocumentService: | |
| def generate_contract_document(self, contract_id: int) -> dict[str, Any]: | |
| service = get_contract_generation_service() | |
| content, filename, error = service.generate_contract_document(contract_id) | |
| if error: | |
| if "不存在" in error: | |
| raise NotFoundError(message=error, code="CONTRACT_NOT_FOUND", errors={}) | |
| raise ValidationException(message=error, code="CONTRACT_GENERATION_FAILED", errors={}) | |
| folder_binding_service = get_contract_folder_binding_service() | |
| binding = folder_binding_service.get_binding(contract_id) | |
| return { | |
| "content": content, | |
| "filename": filename, | |
| "folder_path": binding.folder_path if binding else None, | |
| } | |
| def generate_supplementary_agreement(self, contract_id: int, agreement_id: int) -> dict[str, Any]: | |
| service = get_supplementary_agreement_generation_service() | |
| content, filename, error = service.generate_supplementary_agreement(contract_id, agreement_id) | |
| if error: | |
| if "不存在" in error: | |
| raise NotFoundError(message=error, code="SUPPLEMENTARY_AGREEMENT_NOT_FOUND", errors={}) | |
| raise ValidationException(message=error, code="SUPPLEMENTARY_AGREEMENT_GENERATION_FAILED", errors={}) | |
| folder_binding_service = get_contract_folder_binding_service() | |
| binding = folder_binding_service.get_binding(contract_id) | |
| return { | |
| "content": content, | |
| "filename": filename, | |
| "folder_path": binding.folder_path if binding else None, | |
| } | |