Skip to content

SlugField

Field of Model for automatic generation of string slug.

SlugField

Bases: Field

Field of Model for automatic generation of string slug.

Convenient to use for Url addresses.

Source code in src/ramifice/fields/slug_field.py
class SlugField(Field):
    """Field of Model for automatic generation of string `slug`.

    Convenient to use for Url addresses.
    """

    def __init__(
        self,
        label: str = "",
        placeholder: str = "",
        is_hide: bool = False,
        is_disable: bool = False,
        is_ignore: bool = False,
        hint: str = "",
        warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
        is_readonly: bool = False,
        slug_sources: list[str] = ["id"],  # ruff:ignore[mutable-argument-default]
    ) -> None:
        """Field of Model for automatic generation of string `slug`.

        Convenient to use for Url addresses.

        Agrs:
            label: Text label for a web form field.
            placeholder: Displays prompt text.
            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_readonly: Specifies that the field cannot be modified by the user.
            slug_sources: List of sources fields.
        """
        if Config.DEBUG:
            try:  # ruff:ignore[too-many-statements-in-try-clause]
                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_readonly, bool):
                    raise AssertionError("Parameter `is_readonly` - Not а `bool` type!")
                if not isinstance(slug_sources, list):
                    raise AssertionError("Parameter `slug_sources` - Not а `list` type!")
            except AssertionError as err:
                logger.critical(str(err))
                raise err

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

        field_core: dict[str, Any] = {
            "id": "",
            "name": "",
            "label": label,
            "input_type": "text",
            "value": None,
            "placeholder": placeholder,
            "is_hide": is_hide,
            "is_disable": is_disable,
            "is_ignore": is_ignore,
            "hint": hint,
            "warning": warning,
            "required": False,
            "is_readonly": is_readonly,
            "unique": True,
            "slug_sources": slug_sources,
            "errors": [],
            "field_type": "SlugField",
            "group": "slug",
        }

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

__init__(label='', placeholder='', is_hide=False, is_disable=False, is_ignore=False, hint='', warning=[], is_readonly=False, slug_sources=['id'])

Field of Model for automatic generation of string slug.

Convenient to use for Url addresses.

Agrs

label: Text label for a web form field. placeholder: Displays prompt text. 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_readonly: Specifies that the field cannot be modified by the user. slug_sources: List of sources fields.

Source code in src/ramifice/fields/slug_field.py
def __init__(
    self,
    label: str = "",
    placeholder: str = "",
    is_hide: bool = False,
    is_disable: bool = False,
    is_ignore: bool = False,
    hint: str = "",
    warning: list[str] = [],  # ruff:ignore[mutable-argument-default]
    is_readonly: bool = False,
    slug_sources: list[str] = ["id"],  # ruff:ignore[mutable-argument-default]
) -> None:
    """Field of Model for automatic generation of string `slug`.

    Convenient to use for Url addresses.

    Agrs:
        label: Text label for a web form field.
        placeholder: Displays prompt text.
        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_readonly: Specifies that the field cannot be modified by the user.
        slug_sources: List of sources fields.
    """
    if Config.DEBUG:
        try:  # ruff:ignore[too-many-statements-in-try-clause]
            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_readonly, bool):
                raise AssertionError("Parameter `is_readonly` - Not а `bool` type!")
            if not isinstance(slug_sources, list):
                raise AssertionError("Parameter `slug_sources` - Not а `list` type!")
        except AssertionError as err:
            logger.critical(str(err))
            raise err

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

    field_core: dict[str, Any] = {
        "id": "",
        "name": "",
        "label": label,
        "input_type": "text",
        "value": None,
        "placeholder": placeholder,
        "is_hide": is_hide,
        "is_disable": is_disable,
        "is_ignore": is_ignore,
        "hint": hint,
        "warning": warning,
        "required": False,
        "is_readonly": is_readonly,
        "unique": True,
        "slug_sources": slug_sources,
        "errors": [],
        "field_type": "SlugField",
        "group": "slug",
    }

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