Skip to content

options

django_spire.core.components.form.options

FormOptions dataclass

A row is created and edited in a form component, shown in a modal. Give the application's own component (a :class:ModelFormComponent class or a callable factory such as functools.partial(...)), or a form_class with the template that lays out its fields, which the generic :class:ModelFormComponent shows. The form fires saved with the row's pk.

component = None class-attribute instance-attribute

form_class = None class-attribute instance-attribute

template = None class-attribute instance-attribute

__post_init__

Source code in django_spire/core/components/form/options.py
def __post_init__(self) -> None:
    if self.component is not None:
        if isinstance(self.component, type):
            if not issubclass(self.component, ModelFormComponent):
                message = 'FormOptions.component must be a ModelFormComponent subclass or callable factory.'
                raise ImproperlyConfigured(message)
        elif not callable(self.component):
            message = 'FormOptions.component must be a ModelFormComponent subclass or callable factory.'
            raise ImproperlyConfigured(message)

    if self.component is not None and (
        self.form_class is not None or self.template is not None
    ):
        message = (
            'FormOptions takes a component, or a form_class with a template, '
            'not both: a component declares its own form and template.'
        )
        raise ImproperlyConfigured(message)

    if self.component is None and (self.form_class is None or self.template is None):
        message = (
            'FormOptions needs a component, or a form_class together with a '
            'template.'
        )
        raise ImproperlyConfigured(message)

build_component

Source code in django_spire/core/components/form/options.py
def build_component(self, **parameters: Any) -> ModelFormComponent:
    if self.component is not None:
        built_component = self.component(**parameters)

        if not isinstance(built_component, ModelFormComponent):
            message = (
                f'FormOptions.component factory must return a ModelFormComponent, '
                f'got {type(built_component).__name__}.'
            )
            raise ImproperlyConfigured(message)

        return built_component

    return ModelFormComponent(
        form_class=self.form_class,
        template=self.template,
        **parameters,
    )

PageFormOptions dataclass

A row is created and edited on a page of its own. url_name is the route that takes the row's key as pk. Creating a row goes to create_url_name, which takes no arguments, or when that is left out, to url_name with a pk of 0.

Each link carries a return_url for the page to send the user to afterwards: the route named by return_url_name, or when that is left out, the address the list is shown at. A page that does not read return_url goes wherever it always does.

url_name instance-attribute

create_url_name = None class-attribute instance-attribute

return_url_name = None class-attribute instance-attribute