🔧 chore(base.py): update serialize_display_name method to handle cases where display_name is not set and convert name to title case if title_case is True
This commit is contained in:
parent
09612c82a0
commit
29d176c906
1 changed files with 17 additions and 6 deletions
|
|
@ -60,9 +60,14 @@ 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 = True
|
||||
"""Specifies if the field should be displayed in title case. Defaults to True."""
|
||||
|
||||
def to_dict(self):
|
||||
return self.model_dump(by_alias=True, exclude_none=True)
|
||||
|
||||
|
|
@ -86,9 +91,15 @@ class TemplateField(BaseModel):
|
|||
if value == "float" and self.range_spec is None:
|
||||
self.range_spec = RangeSpec()
|
||||
return value
|
||||
return value
|
||||
return value
|
||||
return value
|
||||
return value
|
||||
return value
|
||||
|
||||
@field_serializer("display_name")
|
||||
def serialize_display_name(self, value, _info):
|
||||
# If display_name is not set, use name and convert to title case
|
||||
# if title_case is True
|
||||
if value is None:
|
||||
# name is probably a snake_case string
|
||||
# Ex: "file_path" -> "File Path"
|
||||
value = self.name.replace("_", " ")
|
||||
if self.title_case:
|
||||
value = value.title()
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue