- Author:
- LaraChicharo
- Posted:
- September 11, 2015
- Language:
- Python
- Version:
- 1.7
- Score:
- 0 (after 0 ratings)
Wraps many Form subclases in order to get a form wizard to treat them as one.
Many Forms will use one step.
Example:
class LanguageVerifiedHumanForm(MultipleForms):
base_forms = [
('language_form', LanguageForm), ('verified_human_form', VerifiedHumanForm)
]
class NewGuideWizard(SessionWizardView):
form_list = [
('guide_form', GuideForm),
('multi_form', LanguageVerifiedHumanForm),
]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from collections import OrderedDict
class MultipleForms(forms.Form):
"""
Wraps many Form subclases in order to get a form wizard to treat them as one.
Args:
base_forms(list): Contains tuples with two elements each: name
and class of the form we want to add.
"""
def set_instances(self):
for name, form in self.base_forms:
form_instance = form(self.data, self.files, prefix=self.prefix)
self.instances_list.append(form_instance)
self.instances_dict.update({name: form_instance})
def __init__(self, *args, **kwargs):
for name, form in self.base_forms:
self.base_fields.update(form.base_fields)
super(MultipleForms, self).__init__(*args, **kwargs)
self.instances_dict = OrderedDict()
self.instances_list = list()
if self.is_bound:
self.set_instances()
|
More like this
- Browser-native date input field by kytta 1 month, 1 week ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 3 weeks ago
- FileField having auto upload_to path by junaidmgithub 3 months ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months, 1 week ago
Comments
Not really well tested btw. Dont use save method on this.
#
Please login first before commenting.