Fieldsets¶
- class tapeforms.fieldsets.TapeformFieldset(form, fields=None, exclude=None, primary=False, template=None, extra=None)[source]¶
Bases:
TapeformLayoutMixin
,object
Class to render a subset of a form’s fields. From a template perspective, a fieldset looks quite similar to a form (and can use the same template tag to render:
form
.- __init__(form, fields=None, exclude=None, primary=False, template=None, extra=None)[source]¶
Initializes a fieldset instance to be used like a form in a template.
Just like in ModelForm Meta, you have to provide at least a list of fields to render in this fieldset or a list of fields to exclude. If you provide both, exclusions have a higher priority.
- Parameters:
form – The form instance to take fields from.
fields – A list of visible field names to include in this fieldset.
exclude – A list of visible fields to _not_ include in this fieldset.
primary – If the fieldset is primary, this fieldset is responsible for rendering the hidden fields and non field errors.
template – You can provide an alternative layout template to use.
extra – This argument is carried around with the fieldset and is also available in the template. Useful to pass some special arguments for rendering around (like a fieldset headline.
- Returns:
A configured fieldset instance.
Returns the hidden fields of the form for rendering of the fieldset is marked as the primary fieldset.
- Returns:
List of bound field instances or empty tuple.
- non_field_errors()[source]¶
Returns all non-field errors of the form for rendering of the fieldset is marked as the primary fieldset.
- Returns:
ErrorList instance with non field errors or empty ErrorList.
- visible_fields()[source]¶
Returns the reduced set of visible fields to output from the form.
This method respects the provided
fields
configuration _and_ exlcudes all fields from theexclude
configuration.If no
fields
where provided when configuring this fieldset, all visible fields minus the excluded fields will be returned.- Returns:
List of bound field instances or empty tuple.
- class tapeforms.fieldsets.TapeformFieldsetsMixin[source]¶
Bases:
object
Mixin to generate fieldsets based on the fieldsets property of a
TapeformFieldsetsMixin
enabled form.- fieldset_class[source]¶
Default fieldset class to use when instantiating a fieldset.
alias of
TapeformFieldset
- get_fieldset_class(**fieldset_kwargs)[source]¶
Returns the fieldset class to use when generating the fieldset using the passed fieldset kwargs.
- Parameters:
fieldset_kwargs –
dict
with the fieldset config fromfieldsets
- Returns:
Class to use when instantiating the fieldset.
- get_fieldset(**fieldset_kwargs)[source]¶
Returns a fieldset instance for the passed
fieldset_kwargs
.- Parameters:
fieldset_kwargs –
dict
with the fieldset config fromfieldsets
- Returns:
Fieldset instance
- get_fieldsets(fieldsets=None)[source]¶
This method returns a generator which yields fieldset instances.
The method uses the optional fieldsets argument to generate fieldsets for. If no fieldsets argument is passed, the class property
fieldsets
is used.When generating the fieldsets, the method ensures that at least one fielset will be the primary fieldset which is responsible for rendering the non field errors and hidden fields.
- Parameters:
fieldsets – Alternative set of fieldset kwargs. If passed this set is prevered of the
fieldsets
property of the form.- Returns:
generator which yields fieldset instances.