From 34f28e9e087ae5e4ec13b54f53617e64bae3f12c Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Thu, 14 Feb 2019 10:45:45 +0100
Subject: [PATCH] Overriding has_changed to allow to mark as delete empty form
 and keep the required attributes

---
 ippisite/ippidb/forms.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/ippisite/ippidb/forms.py b/ippisite/ippidb/forms.py
index ec1fdaf1..44583cc4 100644
--- a/ippisite/ippidb/forms.py
+++ b/ippisite/ippidb/forms.py
@@ -527,6 +527,12 @@ class TestActivityDescriptionForm(forms.ModelForm):
             'ppi': forms.HiddenInput(),
         }
 
+    def has_changed(self):
+        #If only the delete button was checked, and there is no id, it has not changed and thus should be ignored.
+        if len(self.changed_data) == 1 and self.changed_data[0] == "DELETE" and self.data.get("id", None) is None:
+            return False
+        return super().has_changed()
+
 
 class CompoundActivityResultForm(ModelForm):
     class Meta:
@@ -536,6 +542,12 @@ class CompoundActivityResultForm(ModelForm):
             'activity',
         )
 
+    def has_changed(self):
+        #If only the delete button was checked, and there is no id, it has not changed and thus should be ignored.
+        if len(self.changed_data) == 1 and self.changed_data[0] == "DELETE" and self.data.get("id", None) is None:
+            return False
+        return super().has_changed()
+
 
 CompoundActivityResultInlineFormset = inlineformset_factory(
     parent_model=TestActivityDescription,
-- 
GitLab