fairdm.forms.base#

Base form classes configured through options on their Meta.

Module Contents#

Classes#

BaseMetaClass

Metaclass mixin that collects FairDM options from a form’s Meta.

FairDMModelFormMetaclass

Metaclass for :class:ModelForm that reads FairDM Meta options.

FairDMFormMetaclass

Metaclass for :class:Form that reads FairDM Meta options.

FairDMFormMixin

Mixin that applies the FairDM Meta options to a form.

Form

Base form for FairDM, configured through options on its Meta.

ModelForm

Base model form for FairDM, configured through options on its Meta.

API#

class BaseMetaClass[source]#

Metaclass mixin that collects FairDM options from a form’s Meta.

The options are merged with those of the base classes and stored on the form class as _custom_conf. They are removed from Meta so Django never sees them. Meta.fields is flattened, or taken from Meta.fieldsets when set.

class FairDMModelFormMetaclass[source]#

Bases: fairdm.forms.base.BaseMetaClass, django.forms.models.ModelFormMetaclass

Metaclass for :class:ModelForm that reads FairDM Meta options.

class FairDMFormMetaclass[source]#

Bases: fairdm.forms.base.BaseMetaClass, django.forms.forms.DeclarativeFieldsMetaclass

Metaclass for :class:Form that reads FairDM Meta options.

class FairDMFormMixin(*args, **kwargs)[source]#

Mixin that applies the FairDM Meta options to a form.

The options are read by :class:BaseMetaClass into _custom_conf:

  • formfield_overrides: maps a model field type to the form field class used for it. Fields declared on the form are left alone.

  • field_overrides: maps a field name to a dict of attributes set on that field.

  • explicit_fields: when True, drop every field not in Meta.fields.

  • fieldsets: grouped fields, used for the crispy layout and Meta.fields.

  • form_attrs: HTML attributes for the <form> element.

  • helper_attrs: attributes set on the crispy FormHelper.

  • help_text: HTML shown above the form fields.

Initialization

get_layout()[source]#

Build the crispy layout for this form.

Uses fieldsets when configured, then the configured fields, then Meta.fields. Override it to provide a custom layout.

Returns: The layout, empty when the form declares no fields.

get_help_text()[source]#

Build the help text block shown above the form fields.

Override it to provide custom help text.

Returns: A crispy element wrapping the configured help_text, or None when none is configured.

get_form_id()[source]#

Return the form’s HTML id, the lowercased class name by default.

Override it to provide a custom id.

Returns: The id used for the crispy helper’s form_id.

class Form(*args, **kwargs)[source]#

Bases: fairdm.forms.base.FairDMFormMixin, django.forms.Form

Base form for FairDM, configured through options on its Meta.

Initialization

class Meta[source]#
formfield_overrides#

None

explicit_fields#

True

form_attrs: dict[str, Any]#

None

class ModelForm(*args, **kwargs)[source]#

Bases: fairdm.forms.base.FairDMFormMixin, django.forms.ModelForm

Base model form for FairDM, configured through options on its Meta.

Initialization

class Meta[source]#
formfield_overrides#

None

explicit_fields#

True

form_attrs: dict[str, Any]#

None