Skip to content

FloatField

Field of Model for enter (float) number.

FloatField

Bases: Field

Field of Model for enter (float) number.

Source code in src/ramifice/fields/float_field.py
class FloatField(Field):
    """Field of Model for enter (float) number."""

    def __init__(
        self,
        label: str = "",
        placeholder: str = "",
        default: float | None = None,
        is_hide: bool = False,
        is_disable: bool = False,
        is_ignore: bool = False,
        hint: str = "",
        warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
        is_require: bool = False,
        is_readonly: bool = False,
        is_unique: bool = False,
        max_number: float | None = None,
        min_number: float | None = None,
        step: float = 1.0,
        input_type: Literal["number", "range"] = "number",
    ) -> None:
        """Field of Model for enter (float) number.

        Agrs:
            label: Text label for a web form field.
            placeholder: Displays prompt text.
            default: Value by default.
            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.
            is_require: Required field.
            is_readonly: Specifies that the field cannot be modified by the user.
            is_unique: The unique value of a field in a collection.
            max_number: Maximum allowed number.
            min_number: Minimum allowed number.
            step: Increment step for numeric fields.
            input_type: Field type - `number` or `range`.
        """
        if Config.DEBUG:
            try:  # ruff:ignore[too-many-statements-in-try-clause]
                if input_type not in ["number", "range"]:
                    raise AssertionError(
                        "Parameter `input_type` - Invalid input type! "
                        + "The permissible value of `number` or `range`.",
                    )
                if max_number is not None and not isinstance(max_number, float):
                    raise AssertionError("Parameter `max_number` - Not а number `float` type!")
                if min_number is not None and not isinstance(min_number, float):
                    raise AssertionError("Parameter `min_number` - Not а number `float` type!")
                if not isinstance(step, float):
                    raise AssertionError("Parameter `step` - Not а number `float` type!")
                if max_number is not None and min_number is not None and max_number <= min_number:
                    raise AssertionError("The `max_number` parameter should be more than the `min_number`!")
                if default is not None:
                    if not isinstance(default, float):
                        raise AssertionError("Parameter `default` - Not а number `float` type!")
                    if max_number is not None and default > max_number:
                        raise AssertionError("Parameter `default` is more `max_number`!")
                    if max_number is not None and default < min_number:
                        raise AssertionError("Parameter `default` is less `min_number`!")
                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!")
                if not isinstance(placeholder, str):
                    raise AssertionError("Parameter `placeholder` - Not а `str` type!")
                if not isinstance(is_require, bool):
                    raise AssertionError("Parameter `is_require` - Not а `bool` type!")
                if not isinstance(is_readonly, bool):
                    raise AssertionError("Parameter `is_readonly` - Not а `bool` type!")
                if not isinstance(is_unique, bool):
                    raise AssertionError("Parameter `unique` - Not а `bool` type!")
            except AssertionError as err:
                logger.critical(str(err))
                raise err

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

        field_core: dict[str, Any] = {
            "id": "",
            "name": "",
            "label": label,
            "input_type": input_type,
            "value": None,
            "default": default,
            "placeholder": placeholder,
            "is_hide": is_hide,
            "is_disable": is_disable,
            "is_ignore": is_ignore,
            "hint": hint,
            "warning": warning,
            "is_require": is_require,
            "is_readonly": is_readonly,
            "is_unique": is_unique,
            "max_number": max_number,
            "min_number": min_number,
            "step": step,
            "errors": [],
            "field_type": "FloatField",
            "group": "number",
        }

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

__init__(label='', placeholder='', default=None, is_hide=False, is_disable=False, is_ignore=False, hint='', warning=[], is_require=False, is_readonly=False, is_unique=False, max_number=None, min_number=None, step=1.0, input_type='number')

Field of Model for enter (float) number.

Agrs

label: Text label for a web form field. placeholder: Displays prompt text. default: Value by default. 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. is_require: Required field. is_readonly: Specifies that the field cannot be modified by the user. is_unique: The unique value of a field in a collection. max_number: Maximum allowed number. min_number: Minimum allowed number. step: Increment step for numeric fields. input_type: Field type - number or range.

Source code in src/ramifice/fields/float_field.py
def __init__(
    self,
    label: str = "",
    placeholder: str = "",
    default: float | None = None,
    is_hide: bool = False,
    is_disable: bool = False,
    is_ignore: bool = False,
    hint: str = "",
    warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
    is_require: bool = False,
    is_readonly: bool = False,
    is_unique: bool = False,
    max_number: float | None = None,
    min_number: float | None = None,
    step: float = 1.0,
    input_type: Literal["number", "range"] = "number",
) -> None:
    """Field of Model for enter (float) number.

    Agrs:
        label: Text label for a web form field.
        placeholder: Displays prompt text.
        default: Value by default.
        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.
        is_require: Required field.
        is_readonly: Specifies that the field cannot be modified by the user.
        is_unique: The unique value of a field in a collection.
        max_number: Maximum allowed number.
        min_number: Minimum allowed number.
        step: Increment step for numeric fields.
        input_type: Field type - `number` or `range`.
    """
    if Config.DEBUG:
        try:  # ruff:ignore[too-many-statements-in-try-clause]
            if input_type not in ["number", "range"]:
                raise AssertionError(
                    "Parameter `input_type` - Invalid input type! "
                    + "The permissible value of `number` or `range`.",
                )
            if max_number is not None and not isinstance(max_number, float):
                raise AssertionError("Parameter `max_number` - Not а number `float` type!")
            if min_number is not None and not isinstance(min_number, float):
                raise AssertionError("Parameter `min_number` - Not а number `float` type!")
            if not isinstance(step, float):
                raise AssertionError("Parameter `step` - Not а number `float` type!")
            if max_number is not None and min_number is not None and max_number <= min_number:
                raise AssertionError("The `max_number` parameter should be more than the `min_number`!")
            if default is not None:
                if not isinstance(default, float):
                    raise AssertionError("Parameter `default` - Not а number `float` type!")
                if max_number is not None and default > max_number:
                    raise AssertionError("Parameter `default` is more `max_number`!")
                if max_number is not None and default < min_number:
                    raise AssertionError("Parameter `default` is less `min_number`!")
            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!")
            if not isinstance(placeholder, str):
                raise AssertionError("Parameter `placeholder` - Not а `str` type!")
            if not isinstance(is_require, bool):
                raise AssertionError("Parameter `is_require` - Not а `bool` type!")
            if not isinstance(is_readonly, bool):
                raise AssertionError("Parameter `is_readonly` - Not а `bool` type!")
            if not isinstance(is_unique, bool):
                raise AssertionError("Parameter `unique` - Not а `bool` type!")
        except AssertionError as err:
            logger.critical(str(err))
            raise err

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

    field_core: dict[str, Any] = {
        "id": "",
        "name": "",
        "label": label,
        "input_type": input_type,
        "value": None,
        "default": default,
        "placeholder": placeholder,
        "is_hide": is_hide,
        "is_disable": is_disable,
        "is_ignore": is_ignore,
        "hint": hint,
        "warning": warning,
        "is_require": is_require,
        "is_readonly": is_readonly,
        "is_unique": is_unique,
        "max_number": max_number,
        "min_number": min_number,
        "step": step,
        "errors": [],
        "field_type": "FloatField",
        "group": "number",
    }

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