Download apps/contracts/domain/validators.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/contracts/domain/validators.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/contracts/domain/validators.py
-
curl -L -o validators.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/contracts/domain/validators.py
1.14 kB
| """Module for validators.""" | |
| from __future__ import annotations | |
| from collections.abc import Iterable | |
| from django.utils.translation import gettext_lazy as _ | |
| from apps.core.exceptions import ValidationException | |
| from apps.core.models.enums import CaseStage, CaseType | |
| APPLICABLE_TYPES = {CaseType.CIVIL, CaseType.CRIMINAL, CaseType.ADMINISTRATIVE, CaseType.LABOR, CaseType.INTL} | |
| def normalize_representation_stages( | |
| case_type: str | None, | |
| representation_stages: Iterable[str] | None, | |
| strict: bool = False, | |
| ) -> list[str]: | |
| if not case_type or case_type not in APPLICABLE_TYPES: | |
| rep = list(representation_stages or []) | |
| if strict and rep: | |
| raise ValidationException(_("代理阶段不适用于此合同类型"), code="STAGES_NOT_APPLICABLE") | |
| return [] | |
| rep = list(representation_stages or []) | |
| allowed = {c[0] for c in CaseStage.choices} | |
| invalid = set(rep) - allowed | |
| if invalid: | |
| raise ValidationException( | |
| _("无效的代理阶段"), | |
| code="INVALID_STAGES", | |
| errors={"invalid_stages": sorted(invalid)}, | |
| ) | |
| return rep | |