Download apps/core/dto/contracts.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/core/dto/contracts.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/core/dto/contracts.py
-
curl -L -o contracts.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/core/dto/contracts.py
2.98 kB
| """Module for contracts.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import TYPE_CHECKING, Any | |
| if TYPE_CHECKING: | |
| from apps.contracts.models import Contract, SupplementaryAgreement | |
| class ContractDTO: | |
| id: int | |
| name: str | |
| case_type: str | |
| status: str | |
| representation_stages: list[str] | |
| primary_lawyer_id: int | None = None | |
| primary_lawyer_name: str | None = None | |
| fee_mode: str | None = None | |
| fixed_amount: Any | None = None | |
| risk_rate: Any | None = None | |
| is_archived: bool = False | |
| start_date: str | None = None | |
| end_date: str | None = None | |
| def from_model(cls, contract: Contract) -> ContractDTO: | |
| primary_lawyer = getattr(contract, "primary_lawyer", None) | |
| if primary_lawyer is None: | |
| assignments = getattr(contract, "assignments", None) | |
| if assignments is not None: | |
| primary_assignment = assignments.filter(is_primary=True).select_related("lawyer").first() | |
| if primary_assignment is None: | |
| primary_assignment = assignments.select_related("lawyer").order_by("order", "id").first() | |
| if primary_assignment is not None: | |
| primary_lawyer = getattr(primary_assignment, "lawyer", None) | |
| stages = contract.representation_stages | |
| representation_stages: list[str] = stages if isinstance(stages, list) else [] | |
| return cls( | |
| id=contract.id, | |
| name=contract.name, | |
| case_type=contract.case_type, | |
| status=contract.status, | |
| representation_stages=representation_stages, | |
| primary_lawyer_id=primary_lawyer.id if primary_lawyer else None, | |
| primary_lawyer_name=primary_lawyer.real_name if primary_lawyer else None, | |
| fee_mode=contract.fee_mode, | |
| fixed_amount=contract.fixed_amount, | |
| risk_rate=contract.risk_rate, | |
| is_archived=contract.is_archived, | |
| start_date=str(contract.start_date) if contract.start_date else None, | |
| end_date=str(contract.end_date) if contract.end_date else None, | |
| ) | |
| class PartyRoleDTO: | |
| id: int | |
| contract_id: int | |
| client_id: int | |
| client_name: str | |
| role_type: str | |
| is_our_client: bool = False | |
| class SupplementaryAgreementDTO: | |
| id: int | |
| contract_id: int | |
| title: str | |
| content: str | None = None | |
| signed_date: str | None = None | |
| file_path: str | None = None | |
| created_at: str | None = None | |
| def from_model(cls, agreement: SupplementaryAgreement) -> SupplementaryAgreementDTO: | |
| return cls( | |
| id=agreement.id, | |
| contract_id=agreement.contract_id, | |
| title=agreement.name or "", | |
| content=None, | |
| signed_date=None, | |
| file_path=None, | |
| created_at=str(agreement.created_at) if agreement.created_at else None, | |
| ) | |