diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-17 13:52:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-17 13:53:44 +0200 |
commit | c3bb366cb00fd1eaf7d1487a7c8e46b14659d081 (patch) | |
tree | 8c0b91b41ceb45dcfc72bb3ac8d55bc1b945089c /ishtar_common/forms.py | |
parent | 6f78867c8dfa8adb58f8d072d71ee8e52dd660fa (diff) | |
download | Ishtar-c3bb366cb00fd1eaf7d1487a7c8e46b14659d081.tar.bz2 Ishtar-c3bb366cb00fd1eaf7d1487a7c8e46b14659d081.zip |
Parcels: add public domain field - better management of parcel formsets (refs #2284)
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r-- | ishtar_common/forms.py | 23 |
1 files changed, 23 insertions, 0 deletions
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 |