Skip to content

BooleanField

Field of Model for enter boolean value.

BooleanField

Bases: Field

Field of Model for enter boolean value.

Source code in src/ramifice/fields/bool_field.py
class BooleanField(Field):
    """Field of Model for enter boolean value."""

    def __init__(
        self,
        label: str = "",
        default: bool = False,
        is_hide: bool = False,
        is_disable: bool = False,
        is_ignore: bool = False,
        hint: str = "",
        warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
    ) -> None:
        """Field of Model for enter boolean value.

        Args:
            label: Text label for a web form field.
            default: Default value.
            is_hide: Hide field from user.
            is_disable: Blocks access and modification of the element.
            is_ignore: If true, the value of this field is not saved in the database.
            hint: An alternative for the `placeholder` parameter.
            warning: Warning information.
        """
        if Config.DEBUG:
            try:  # ruff:ignore[too-many-statements-in-try-clause]
                if default is not None and not isinstance(default, bool):
                    raise AssertionError("Parameter `default` - Not а `bool` type!")
                if not isinstance(label, str):
                    raise AssertionError("Parameter `label` - Not а `str` type!")
                if not isinstance(is_disable, bool):
                    raise AssertionError("Parameter `is_disable` - Not а `bool` type!")
                if not isinstance(is_hide, bool):
                    raise AssertionError("Parameter `is_hide` - Not а `bool` type!")
                if not isinstance(is_ignore, bool):
                    raise AssertionError("Parameter `is_ignore` - Not а `bool` type!")
                if not isinstance(hint, str):
                    raise AssertionError("Parameter `hint` - Not а `str` type!")
                if not isinstance(warning, list):
                    raise AssertionError("Parameter `warning` - Not а `list` type!")
            except AssertionError as err:
                logger.critical(str(err))
                raise err

        Field.__init__(self, supported_types=(bool, type(None)))

        field_core: dict[str, Any] = {
            "id": "",
            "name": "",
            "label": label,
            "input_type": "checkbox",
            "value": None,
            "default": default,
            "is_hide": is_hide,
            "is_disable": is_disable,
            "is_ignore": is_ignore,
            "hint": hint,
            "warning": warning,
            "errors": [],
            "field_type": "BooleanField",
            "group": "bool",
        }

        self.__dict__["field_core"] = FieldCore(**field_core)

__init__(label='', default=False, is_hide=False, is_disable=False, is_ignore=False, hint='', warning=[])

Field of Model for enter boolean value.

Parameters:

Name Type Description Default
label str

Text label for a web form field.

''
default bool

Default value.

False
is_hide bool

Hide field from user.

False
is_disable bool

Blocks access and modification of the element.

False
is_ignore bool

If true, the value of this field is not saved in the database.

False
hint str

An alternative for the placeholder parameter.

''
warning list[str]

Warning information.

[]
Source code in src/ramifice/fields/bool_field.py
def __init__(
    self,
    label: str = "",
    default: bool = False,
    is_hide: bool = False,
    is_disable: bool = False,
    is_ignore: bool = False,
    hint: str = "",
    warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
) -> None:
    """Field of Model for enter boolean value.

    Args:
        label: Text label for a web form field.
        default: Default value.
        is_hide: Hide field from user.
        is_disable: Blocks access and modification of the element.
        is_ignore: If true, the value of this field is not saved in the database.
        hint: An alternative for the `placeholder` parameter.
        warning: Warning information.
    """
    if Config.DEBUG:
        try:  # ruff:ignore[too-many-statements-in-try-clause]
            if default is not None and not isinstance(default, bool):
                raise AssertionError("Parameter `default` - Not а `bool` type!")
            if not isinstance(label, str):
                raise AssertionError("Parameter `label` - Not а `str` type!")
            if not isinstance(is_disable, bool):
                raise AssertionError("Parameter `is_disable` - Not а `bool` type!")
            if not isinstance(is_hide, bool):
                raise AssertionError("Parameter `is_hide` - Not а `bool` type!")
            if not isinstance(is_ignore, bool):
                raise AssertionError("Parameter `is_ignore` - Not а `bool` type!")
            if not isinstance(hint, str):
                raise AssertionError("Parameter `hint` - Not а `str` type!")
            if not isinstance(warning, list):
                raise AssertionError("Parameter `warning` - Not а `list` type!")
        except AssertionError as err:
            logger.critical(str(err))
            raise err

    Field.__init__(self, supported_types=(bool, type(None)))

    field_core: dict[str, Any] = {
        "id": "",
        "name": "",
        "label": label,
        "input_type": "checkbox",
        "value": None,
        "default": default,
        "is_hide": is_hide,
        "is_disable": is_disable,
        "is_ignore": is_ignore,
        "hint": hint,
        "warning": warning,
        "errors": [],
        "field_type": "BooleanField",
        "group": "bool",
    }

    self.__dict__["field_core"] = FieldCore(**field_core)