Class: BaseFormMixin¶
The BaseFormMixin class provides useful helper methods for working
with forms - in particular for Cubane’s backend system.
The mixin is used for both, BaseForm and BaseModelForm.
-
class
BaseFormMixin¶ Provides common helper methods for forms.
-
is_tabbed¶ Return
Trueif the form is tabbed.
-
has_sections¶ Return
Trueif the form has at least one section.
-
has_visibility_rules¶ Return
Trueif the form has at least one visibility rule.
-
has_blueprint_rules¶ Return
Trueif this form has at least one blueprint rule.
-
has_limit_rules¶ Return
Trueif this form has at least one character limit rule.
-
tabs¶ Return a list of all tabs.
-
excluded_fields¶ Return a list of form field names that are excluded from this form. Excluded form fields are not processed by this form.
-
is_duplicate¶ Return
Trueif this form is being used to duplicate an instance.
-
has_line_items¶ Return
Trueif at least one form fields is based onRelatedEditFieldwhich presents multiple editable forms that are embedded within this form.
-
setup_initial(self)¶ Called by the constructor of
BaseFormandBaseModelFormin order to setup the initial form data of this form.
-
setup(self)¶ Called by the constructor of
BaseFormandBaseModelFormin order to setup the form including layout, tabs, sections etc.
-
required_fields(self)¶ Return a list of bound form fields that are required.
-
are_all_fields_requried()¶ Return
Trueif all form fields of this form are required.
-
has_required_fields()¶ Return
Trueif at least one form field is required.
-
configure(self, request, instance=None, edit=True)¶ Called before a form is being validated and allows for form configuration to be carried out, such as dynamically removing form fields or making field required or not required.
Parameters: - request (string) – The request object.
- instance (string) – Reference to the model instance that is being edited or created.
- edit (string) –
Trueif a model instance is edited rathe than being created.
-
get_tab_by_title(self, title)¶ Return information about the tab with the given title name.
Parameters: title (string) – The name of tab for which information is returned.
-
remove_tab(self, title, remove_fields=False)¶ Remove the tab with the given name and optionally remove all form fields alongside with it.
Parameters: - title (string) – The name of tab that is being removed.
- remove_fields (string) –
Trueif form fields of the corresponding tab should also be removed alongside the tab. Default:False.
-
remove_tabs(self)¶ Remove all tabs, leaving the form as a non-tabbed form.
-
has_tab(self, title)¶ Return
Trueif there is at least one tab.
-
remove_field(self, fieldname, if_exists=False)¶ Remove the form field with the given name.
Parameters: - fieldname (string) – The name of the form field that is removed.
- if_exists (string) –
Trueto avoid raising an error if the form field does not exist.
-
remove_fields(self, fieldnames, if_exists=False)¶ Remove multiple form fields from the form.
Parameters: - fieldnames (string) – List of form field names that will be removed from the form.
- if_exists (string) –
Trueto avoid raising an error if any form field does not exist.
-
field_error(self, fieldname, msg)¶ Generates a form error condition with the given error message for the given form field.
Parameters: - fieldname (string) – Name of the form field for which an error condition is raised.
- msg (string) – Error message that is being raised.
-
update_sections(self, collect=True)¶ Update the internal list of sections for this form, which may become necessarily whenever form fields are manipulated - in particular when being removed.
Parameters: collect (string) – Trueif sections not only be re-created but also re-collected from all derived classes (default).
-
get_encoded_visibility_rules(self)¶ Return a list of all visibility rules for this form encoded as a JSON string.
-
get_encoded_blueprint_rules(self)¶ Return a list of all blueprint rules for this form encoded as a JSON string.
-
get_encoded_limit_rules(self)¶ Return a list of character limitation rules for this form encoded as a JSON string.
-
to_dict(self)¶ Return a representation of this form as a dictionary.
-