51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import unicodedata
|
|
from enum import Enum
|
|
from typing import Union, Optional
|
|
|
|
|
|
def _normalize_no_accents(s: str) -> str:
|
|
"""Normalise une chaîne en supprimant les accents et en la passant en minuscule."""
|
|
return "".join(c for c in unicodedata.normalize("NFKD", s) if not unicodedata.combining(c)).lower()
|
|
|
|
|
|
class ProspectStatus(str, Enum):
|
|
NOUVEAU = "Nouveau"
|
|
CONTACTE = "Contacté"
|
|
RELANCE = "Relancé"
|
|
QUALIFIE = "Qualifié"
|
|
PROPOSITION = "Proposition"
|
|
NON_INTERESSE = "Non intéressé"
|
|
|
|
@classmethod
|
|
def from_value(cls, value: Optional[Union["ProspectStatus", str]]) -> "ProspectStatus":
|
|
"""Convertit une valeur (enum ou chaîne) en ProspectStatus, avec tolérance sur la casse/accents."""
|
|
if isinstance(value, cls):
|
|
return value
|
|
if value is None:
|
|
return cls.NOUVEAU
|
|
s = str(value).strip()
|
|
if not s:
|
|
return cls.NOUVEAU
|
|
|
|
n = _normalize_no_accents(s)
|
|
|
|
if n in {"nouveau", "new"}:
|
|
return cls.NOUVEAU
|
|
if n in {"contacte", "contacted"}:
|
|
return cls.CONTACTE
|
|
if n in {"relance", "relaunched"}:
|
|
return cls.RELANCE
|
|
if n in {"qualifie", "qualified"}:
|
|
return cls.QUALIFIE
|
|
if n in {"proposition", "proposal"}:
|
|
return cls.PROPOSITION
|
|
if n in {"non interesse", "noninteresse", "not interested", "refuse", "refus", "abandon"}:
|
|
return cls.NON_INTERESSE
|
|
|
|
# Tentative de correspondance exacte insensible aux accents/casse avec les valeurs de l'enum
|
|
for member in cls:
|
|
if _normalize_no_accents(member.value) == n:
|
|
return member
|
|
|
|
# Valeur inconnue -> par défaut
|
|
return cls.NOUVEAU
|