From a39de3c54cf2f76cd40dd83a0f780e8780267c0c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 17 Aug 2016 13:52:44 +0200 Subject: Parcels: add public domain field - better management of parcel formsets (refs #2284) --- ishtar_common/forms.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index b851c95b2..2e170fd1e 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -164,6 +164,29 @@ def get_form_selection( return type(class_name, (forms.Form,), attrs) +def get_data_from_formset(data): + """ + convert ['formname-wizardname-1-public_domain': [u'on'], ...] to + [{'public_domain': 'off'}, {'public_domain': 'on'}] + """ + values = [] + for k in data: + if not data[k]: + continue + keys = k.split('-') + if len(keys) < 3: + continue + try: + idx = int(keys[-2]) + except ValueError: + continue + while len(values) < (idx + 1): + values.append({}) + field_name = keys[-1] + values[idx][field_name] = data[k] + return values + + class DocumentGenerationForm(forms.Form): """ Form to generate document by choosing the template -- cgit v1.2.3