From 62d0ed78f4065fe820aeb60eae82ad68b2a94103 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 9 Apr 2024 12:50:55 +0200
Subject: [PATCH] allow removal/emptying of funding statements

fixes #89
---
 scipost_django/journals/forms.py | 3 ++-
 scipost_django/journals/views.py | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/scipost_django/journals/forms.py b/scipost_django/journals/forms.py
index 3b38810ff..04760df64 100644
--- a/scipost_django/journals/forms.py
+++ b/scipost_django/journals/forms.py
@@ -191,7 +191,8 @@ class AbstractJATSForm(forms.ModelForm):
 
 class FundingInfoForm(forms.ModelForm):
     funding_statement = forms.CharField(
-        widget=forms.Textarea({"placeholder": "Paste the funding info statement here"})
+        required=False,
+        widget=forms.Textarea({"placeholder": "Paste the funding info statement here"}),
     )
 
     class Meta:
diff --git a/scipost_django/journals/views.py b/scipost_django/journals/views.py
index 8e09a3f32..f9f458018 100644
--- a/scipost_django/journals/views.py
+++ b/scipost_django/journals/views.py
@@ -960,6 +960,15 @@ class FundingInfoView(
     form_class = FundingInfoForm
     template_name = "journals/create_funding_info_metadata.html"
 
+    # Delete the funding statement if the form is submitted empty
+    def form_valid(self, form):
+        if form.cleaned_data.get("funding_statement", "") == "":
+            self.object.metadata["funding_statement"] = ""
+            self.object.save()
+            return redirect(self.get_success_url())
+
+        return super().form_valid(form)
+
 
 @permission_required("scipost.can_draft_publication", return_403=True)
 @transaction.atomic
-- 
GitLab