summaryrefslogtreecommitdiff
path: root/ishtar_common/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-23 11:55:39 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-23 11:55:39 +0200
commitbfd0d7e3e576c700968c1eb8571f32649274b18e (patch)
tree823b43e3689dc2a66a28cc2c9271d5b17d039dd2 /ishtar_common/forms.py
parent29e6b089568281bfa5a3dcff80f9fca8b42852af (diff)
parentd4f335cc6990eb86e011b5f58f01cf92a89ddd87 (diff)
downloadIshtar-bfd0d7e3e576c700968c1eb8571f32649274b18e.tar.bz2
Ishtar-bfd0d7e3e576c700968c1eb8571f32649274b18e.zip
Merge branch 'v0.9' into wheezy
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r--ishtar_common/forms.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 5e0d14eb8..89df1b1a5 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -124,6 +124,13 @@ class ClosingDateFormSelection(forms.Form):
end_date = forms.DateField(label=_(u"Closing date"),
widget=widgets.JQueryDate)
+ def __init__(self, *args, **kwargs):
+ if 'initial' not in kwargs:
+ kwargs['initial'] = {}
+ if not kwargs['initial'].get('end_date', None):
+ kwargs['initial']['end_date'] = datetime.date.today()
+ super(ClosingDateFormSelection, self).__init__(*args, **kwargs)
+
def get_form_selection(
class_name, label, key, model, base_form, get_url,
@@ -164,6 +171,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