22 lines
714 B
Python
22 lines
714 B
Python
"""Common base for every import schema."""
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
from webapi.imports.schemas.coercion import Catalog
|
|
|
|
|
|
class ImportSchema(BaseModel):
|
|
"""Shared pydantic config for all import schemas.
|
|
|
|
`coerce_numbers_to_str`: a numeric source column (SQL INT, Excel number,
|
|
JSON number) feeding a text field is legitimate: expediente `12345` is "12345".
|
|
"""
|
|
|
|
model_config = ConfigDict(coerce_numbers_to_str=True)
|
|
|
|
@classmethod
|
|
def catalog_for(cls, field_name: str) -> Catalog | None:
|
|
field = cls.model_fields.get(field_name)
|
|
if field is None:
|
|
return None
|
|
return next((m for m in field.metadata if isinstance(m, Catalog)), None)
|