Forms

class ajaxviews.forms.DefaultFormActions[source]

Bases: crispy_forms.layout.LayoutObject

Crispy layout object that renders form actions depending on options defined in form.opts property.

Keyword arguments available in opts:

Variables:
  • success_url (str) – Url to redirect to on successful form save.
  • delete_url (str) – Delete view that’s requested on form delete.
  • delete_success_url (str) – Url to redirect view on successful form deletion.
  • form_actions_template (str) – Template to render form actions in. Default: 'ajaxviews/_form_controls.html'
  • preview_stage (int) – If form preview is displayed render a back button.
  • modal_form (bool) – True if form is displayed in a bootrap modal. Default: False
  • delete_confirmation (bool) – Display a bootstrap confirmation popover if delete button is clicked.
  • form_cfg (dict) – Additional data needed to process form save passed through a hidden input field. Dictionary is stringified and automatically parsed again when calling FormMixin.cleaned_form_cfg().
class ajaxviews.forms.DefaultFormHelper(*args, **kwargs)[source]

Bases: crispy_forms.helper.FormHelper

Crispy form helper used to define default form action control.

A data-async html property is added to the form tag.

add_form_actions_only()[source]

Disable the form tag and add form actions only to the current layout.

append_form_actions()[source]

Append form actions to the current layout.

class ajaxviews.forms.FormMixin(*args, **kwargs)[source]

Bases: object

Mixin that handels instantiation of crispy form helper and options passed in the form’s init kwargs.

Variables:opts (dict) –
cleaned_form_cfg

Loads the stringified form_cfg in cleaned_data to return a python dictionary object.

Returns:form cfg dictionary
helper

The DefaultFormHelper is instantiated only once when this helper property is accessed first.

Assign your own form helper if you want to override the default behavior.

This renders hidden fields and appends form actions by default.

Returns:Form helper instance
layout

Get or set the crispy form helper layout object. If you set a new layout the form actions are appended automatically.

class ajaxviews.forms.GenericModelForm(*args, **kwargs)[source]

Bases: ajaxviews.forms.FormMixin, django.forms.models.ModelForm

Generic form for use with a corresponding model.

Get model instance with pk of related model from the calling view.

Parameters:
  • model – Django model class.
  • key – Keyword argument to get the value used to retrieve the model instance. If not specified it expects a single key in related_obj_ids that’s used.
Returns:

Model instance.

class ajaxviews.forms.ModelFormSet(*args, **kwargs)[source]

Bases: django.forms.models.BaseModelFormSet

Use this form to render form actions at the bottom of the formset.

Variables:form_actions_template (str) – Template to render save and cancel buttons. Be sure to use the {{ success_url }} tag for your cancel button if you want to override this template.
class ajaxviews.forms.SimpleForm(*args, **kwargs)[source]

Bases: ajaxviews.forms.FormMixin, django.forms.forms.Form

Generic form for use without a corresponding model. Also used to display a preview before saving a form.

Variables:
  • object (object) – Model instance of the preview forms first stage.
  • model_data (dict) – Cleaned data of the preview forms second stage.