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
commitdaeeeb175835559724c8520f4f5a8dcd5957a469 (patch)
tree8b9137dd9b68121db86e4e22dfdb7b7016a6f1ad /ishtar_common
parent8bbba5a30505ceec52b6192dd155f59ab1a8b7c4 (diff)
downloadIshtar-daeeeb175835559724c8520f4f5a8dcd5957a469.tar.bz2
Ishtar-daeeeb175835559724c8520f4f5a8dcd5957a469.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