From 2ba6d441ccd9729e9f4aaf54d7627b3e7092aed0 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 26 Mar 2024 11:53:50 +0100 Subject: [PATCH] allow only pdf files in submission form fixes #74 --- scipost_django/submissions/forms/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scipost_django/submissions/forms/__init__.py b/scipost_django/submissions/forms/__init__.py index 13f472d8c..17d4e8af4 100644 --- a/scipost_django/submissions/forms/__init__.py +++ b/scipost_django/submissions/forms/__init__.py @@ -1471,9 +1471,20 @@ class SubmissionForm(forms.ModelForm): Check that the submitted material fits one of the Journal's options. """ submitted_types = [] - if self.cleaned_data.get("preprint_file", None) or self.cleaned_data.get( - "preprint_link", None - ): + if preprint_file := self.cleaned_data.get("preprint_file"): + submitted_types.append(PUBLISHABLE_OBJECT_TYPE_ARTICLE) + + # Check the file extension + source_file_extensions = ["tex", "zip", "tar", "doc", "docx", "odf"] + extension = preprint_file.name.split(".")[-1].lower() + if extension != "pdf": + error_message = "Please submit a .pdf file. " + if extension in source_file_extensions: + error_message += "We ask for your source files upon acceptance." + + self.add_error("preprint_file", error_message) + + elif self.cleaned_data.get("preprint_link"): submitted_types.append(PUBLISHABLE_OBJECT_TYPE_ARTICLE) if self.cleaned_data.get("code_repository_url", None): submitted_types.append(PUBLISHABLE_OBJECT_TYPE_CODEBASE) -- GitLab