rebar Package¶
rebar
Package¶
group
Module¶
-
class
rebar.group.
FormGroup
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, label_suffix=':', instance=<rebar.group.Unspecified object>, error_class=None, member_kwargs=None)¶ Bases:
object
Form-like wrapper for a heterogenous collection of Forms.
A FormGroup collects an ordered set of Forms and/or FormSets, and provides convenience methods for validating the group as a whole.
-
add_prefix
(field_name)¶ Return the field name with a prefix prepended.
-
clean
()¶ Hook for doing formgroup-wide cleaning/validation.
Subclasses can override this to perform validation after .clean() has been called on every member.
Any ValidationError raised by this method will be accessible via formgroup.group_errors().()
-
errors
¶
-
forms
¶
-
get_default_prefix
()¶
-
group_errors
()¶ Return the group level validation errors.
Returns an ErrorList of errors that aren’t associated with a particular form. Returns an empty ErrorList if there are none.
-
html_id
(field_name, form=None)¶ Return the html ID for the given field_name.
-
is_valid
()¶
-
media
¶
-
save
()¶ Save the changes to the instance and any related objects.
-
-
class
rebar.group.
StateValidatorFormGroup
(*args, **kwargs)¶ Bases:
rebar.validators.StateValidatorFormMixin
,rebar.group.FormGroup
Subclasses are expected to define the state_validators property, which is a mapping of states to StateValidator objects.
-
get_errors
(*states)¶
-
is_valid
(*states)¶ Returns True if no errors are thrown for the specified state.
-
-
rebar.group.
formgroup_factory
(form_classes, formgroup=None, state_validators=None)¶ Return a FormGroup class for the given form[set] form_classes.
testing
Module¶
Tools for testing Forms, FormSets, and FormGroups.
-
rebar.testing.
empty_form_data
(formset, index=None)¶ Return a form data dictionary for a “new” form in a formset.
Given a formset and an index, return a copy of the empty form data. If index is not provided, the index of the first empty form will be used as the new index.
-
rebar.testing.
flatten_to_dict
(item)¶ Recursively flatten a Form-like object to a data dict.
Given a Form-like object such as a Form, ModelForm, FormSet, or FormGroup, flatten the members into a single dict, similar to what is provided by request.POST.
If
item
is a FormSet, all member Forms will be included in the resulting data dictionary
validators
Module¶
-
class
rebar.validators.
StateValidator
¶ Bases:
object
Field Validators which must pass for an object to be in a state.
-
disable
()¶ Disable the validator; when disabled, no errors will be returned.
-
enable
()¶ Enable the validators.
-
enabled
¶
-
errors
(instance)¶ Run all field validators and return a dict of errors.
The keys of the resulting dict coorespond to field names. instance can be a dict (ie, form.cleaned_data), a form, a formset, or a model instance.
If instance is a form, full_clean() will be called if the form is bound.
If instance is a formset, full_clean() will be called on each member form, if bound.
-
is_valid
(instance)¶ Return True if no errors are raised when validating instance.
instance can be a dict (ie, form.cleaned_data), a form, or a model instance. If instance is a form, full_clean() will be called.
-
validators
= {}¶
-
-
class
rebar.validators.
StateValidatorFormMixin
(*args, **kwargs)¶ Bases:
object
Mixin for adding state validators to forms.
Subclasses are expected to define the state_validators property, which is a mapping of states to StateValidator objects.
-
get_errors
(state)¶ Return any validation errors raised for the specified state.
-
is_valid
(*states)¶ Returns True if no errors are thrown for the specified state.
-
state_validators
= {}¶
-
-
rebar.validators.
statevalidator_factory
(field_validators, validator=<class 'rebar.validators.StateValidator'>)¶ Return a StateValidator Class with the given validators.