diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-10 17:30:03 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-10 17:30:03 +0100 |
commit | 9eced41d76545bd2921605b7b81bd14b875ce541 (patch) | |
tree | 8b9137dd9b68121db86e4e22dfdb7b7016a6f1ad /ishtar_common/forms.py | |
parent | 9db820c7d0d47c6116a977b2e4c57f6d36ff3b46 (diff) | |
download | Ishtar-9eced41d76545bd2921605b7b81bd14b875ce541.tar.bz2 Ishtar-9eced41d76545bd2921605b7b81bd14b875ce541.zip |
Formset: delete empty forms
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r-- | ishtar_common/forms.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 18e32cd76..91e9fb3e9 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -436,6 +436,22 @@ class FormSet(CustomForm, BaseFormSet): form.fields[DELETION_FIELD_NAME].label = '' form.fields[DELETION_FIELD_NAME].widget = self.delete_widget() + def _should_delete_form(self, form): + """ + Returns whether or not the form was marked for deletion. + If no data, set deletion to True + """ + if form.cleaned_data.get(DELETION_FIELD_NAME, False): + return True + if not form.cleaned_data or not [ + __ for __ in form.cleaned_data + if __ != DELETION_FIELD_NAME and + form.cleaned_data[__] is not None and + form.cleaned_data[__] != '']: + form.cleaned_data[DELETION_FIELD_NAME] = True + return True + return False + class FormSetWithDeleteSwitches(FormSet): delete_widget = widgets.DeleteSwitchWidget |