configpanel: is_action_section as attr

This commit is contained in:
axolotle 2023-04-24 15:10:27 +02:00
parent d370cb0b24
commit 51d302bf18

View file

@ -86,6 +86,7 @@ class ContainerModel(BaseModel):
class SectionModel(ContainerModel, OptionsModel): class SectionModel(ContainerModel, OptionsModel):
visible: Union[bool, str] = True visible: Union[bool, str] = True
optional: bool = True optional: bool = True
is_action_section: bool = False
# Don't forget to pass arguments to super init # Don't forget to pass arguments to super init
def __init__( def __init__(
@ -99,7 +100,7 @@ class SectionModel(ContainerModel, OptionsModel):
**kwargs, **kwargs,
) -> None: ) -> None:
options = self.options_dict_to_list(kwargs, optional=optional) options = self.options_dict_to_list(kwargs, optional=optional)
is_action_section = any([option["type"] == OptionType.button for option in options])
ContainerModel.__init__( ContainerModel.__init__(
self, self,
id=id, id=id,
@ -108,12 +109,9 @@ class SectionModel(ContainerModel, OptionsModel):
help=help, help=help,
visible=visible, visible=visible,
options=options, options=options,
is_action_section=is_action_section,
) )
@property
def is_action_section(self) -> bool:
return any([option.type is OptionType.button for option in self.options])
def is_visible(self, context: dict[str, Any]) -> bool: def is_visible(self, context: dict[str, Any]) -> bool:
if isinstance(self.visible, bool): if isinstance(self.visible, bool):
return self.visible return self.visible