form
django_spire.core.components.form
__all__ = ['BaseFormComponent', 'FormComponent', 'FormOptions', 'ModelFormComponent', 'PageFormOptions']
module-attribute
BaseFormComponent
Bases: Component, ABC
Shows one form. The form class and the template are set on a subclass,
as form_class and template, or passed when the component is built::
ModelFormComponent(form_class=TaskForm, template='task/form.html')
Either way the form class must be importable from its module, because the component is rebuilt on each request from its signed path.
glue_form_path() is the dot path to the form, read by the template
and its partials as component.glue_form_path. glue_form_object_name
is the name the form's Alpine scope gives it, so a template can call it
account_form instead of glue_form. Whether the component is shown
in a modal, inline or on a page is the choice of whoever shows it.
Source code in django_spire/core/components/form/base_component.py
form_base = BaseForm
class-attribute
form_class = None
class-attribute
glue_form_object_name = 'glue_form'
class-attribute
form_path = Glue.ComponentParameter(None)
class-attribute
instance-attribute
template_name = Glue.ComponentParameter(None)
class-attribute
instance-attribute
template = kwargs['template_name']
instance-attribute
__init_subclass__
validate_form_class
classmethod
Source code in django_spire/core/components/form/base_component.py
glue_form_path
abstractmethod
FormComponent
Bases: BaseFormComponent
A :class:BaseFormComponent over a plain form, exposed as the form
child. Override get_form() when the form needs constructor arguments
from the component's parameters.
Source code in django_spire/core/components/form/base_component.py
form
get_form
ModelFormComponent
Bases: BaseFormComponent
A :class:BaseFormComponent over a ModelForm, whose model is the
form's own. model_pk=None opens the create flow and a value opens the
edit flow. The row is exposed as the model child, a Glue.model, so
the form lives at component.model.form.
The data for the child comes from two overridable hooks: get_model()
picks the instance (blank or fetched by model_pk by default), and
get_fields() names the exposed fields (the form's own fields unless
fields is set), so scoping and create defaults stay subclass logic.
A relation field's choices are the form's own: its __init__ narrows a
field's queryset, which the form child reads, with the row as
self.instance.
pk is the deprecated name of model_pk, both as a parameter and as
an attribute.
Source code in django_spire/core/components/form/model_component.py
form_base = ModelForm
class-attribute
instance-attribute
form_class = None
class-attribute
fields = None
class-attribute
model_pk = Glue.ComponentParameter(None)
class-attribute
instance-attribute
pk
property
model
Source code in django_spire/core/components/form/model_component.py
get_initial
get_fields
Source code in django_spire/core/components/form/model_component.py
get_model
Source code in django_spire/core/components/form/model_component.py
get_permission_model
Return the form's model, whose permissions Glue.ModelAccessMixin reads.
get_required_access
ADD to create a row and CHANGE to edit one, for Glue.ModelAccessRequiredMixin.
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
build_component
Source code in django_spire/core/components/form/options.py
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.