streamline.forms¶
This module contains mixins and classes for working with forms.
-
class
streamline.forms.
FormAdaptor
(data={})¶ This class servers as an adaptor for 3rd party form APIs that works with the default form-handling API in this module. It can also be used on its own as it provides basic means of performing validation of form data.
The adaptor is instantiated with a dict-like object (usually
FormsDict
).-
is_valid
()¶ Perform validation and return a boolean result.
-
-
class
streamline.forms.
FormBase
¶ Base mixin for form-related CBRH.
-
get
(*args, **kwargs)¶ Delegate to
show_form()
.
-
post
(*args, **kwargs)¶ Delegate to
validate()
.
-
-
class
streamline.forms.
FormMixin
¶ Mixin that provides form-related functionality. The methods and properties in this class are implemented in a way that allows easy customization for any form API by focusing on the workflow rather than concreate APIs.
-
form_factory
¶ alias of
FormAdaptor
-
form_invalid
(*args, **kwargs)¶ Handle negative form validation outcome.
-
form_valid
(*args, **kwargs)¶ Handle positive form validation outcome.
-
get_bound_form
()¶ Return bound form object.
-
get_form
()¶ Return form object. Depending on the HTTP verb, this method returns either an unbound (GET) or a bound (all other verbs) form. Once a form object is created, this method will keep returning the previously created instance.
-
get_form_factory
()¶ Return form factory function/class. Default behvarior is to return the
form_factory
property.
-
get_unbound_form
()¶ Return unbound form object.
-
show_form
(*args, **kwargs)¶ Prepare for rendering a blank, unbound form.
-
validate
(*args, **kwargs)¶ Branch to one of the outcome methods depending on form validation result. The business logic should be writen in the outcome methods
form_valid()
andform_invalid()
.Warning
An object that includes this mixin must set its
form
property to a form object before this method is invoked. Failure to do this will result inAttributeError
. This is automatically handled in classes that include theFormBase
mixin.
-
validate_form
(form)¶ Perform validation and return the results of validation.
-
-
class
streamline.forms.
FormRoute
(*args, **kwargs)¶ Class for form handling without templates.
Subclasses: RouteBase
Includes: FormMixin
,FormBase
-
streamline.forms.
ROCAFormRoute
¶ alias of
XHRPartialFormRoute
-
class
streamline.forms.
TemplateFormRoute
(*args, **kwargs)¶ Class for form handling with template rendering.
Subclasses: TemplateRoute
Includes: FormMixin
,FormBase
-
class
streamline.forms.
XHRPartialFormRoute
(*args, **kwargs)¶ Class for form handling with XHR partial rendering support.
Subclasses: XHRPartialRoute
Includes: FormMixin
FormBase