summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
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
commit9eced41d76545bd2921605b7b81bd14b875ce541 (patch)
tree8b9137dd9b68121db86e4e22dfdb7b7016a6f1ad /ishtar_common
parent9db820c7d0d47c6116a977b2e4c57f6d36ff3b46 (diff)
downloadIshtar-9eced41d76545bd2921605b7b81bd14b875ce541.tar.bz2
Ishtar-9eced41d76545bd2921605b7b81bd14b875ce541.zip
Formset: delete empty forms
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py16
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