diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-23 11:07:45 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-23 11:07:45 +0200 |
commit | 7924c43af9044cfd40f36bd8a84378417223d95b (patch) | |
tree | 78197ea5c36baaff4fcc1a53580eb3d586630b39 /ishtar_common/forms.py | |
parent | 54b87741a26a2bd805ed32200b082ca07ee0e27d (diff) | |
parent | 0bdaa7c90017b436b3baf026c9710a8d49c9420a (diff) | |
download | Ishtar-7924c43af9044cfd40f36bd8a84378417223d95b.tar.bz2 Ishtar-7924c43af9044cfd40f36bd8a84378417223d95b.zip |
Merge branch 'master' into v0.9
Conflicts:
ishtar_common/migrations/0053_auto__add_field_ishtarsiteprofile_currency.py
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r-- | ishtar_common/forms.py | 32 |
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 |