Refactor TemplateField class in base.py

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-05 23:15:36 -03:00
commit ee86334286

View file

@ -68,7 +68,9 @@ class TemplateField(BaseModel):
refresh: Optional[bool] = None
"""Specifies if the field should be refreshed. Defaults to False."""
range_spec: Optional[RangeSpec] = Field(default=None, serialization_alias="rangeSpec")
range_spec: Optional[RangeSpec] = Field(
default=None, serialization_alias="rangeSpec"
)
"""Range specification for the field. Defaults to None."""
title_case: bool = False
@ -88,6 +90,8 @@ class TemplateField(BaseModel):
result["input_types"].append("Text")
if self.field_type == "Text":
result["type"] = "str"
else:
result["type"] = self.field_type
return result
@field_serializer("file_path")
@ -117,6 +121,10 @@ class TemplateField(BaseModel):
if not isinstance(value, list):
raise ValueError("file_types must be a list")
return [
(f".{file_type}" if isinstance(file_type, str) and not file_type.startswith(".") else file_type)
(
f".{file_type}"
if isinstance(file_type, str) and not file_type.startswith(".")
else file_type
)
for file_type in value
]