From 5eaa09c10d7d83da48d645b96934d5113bc7ae59 Mon Sep 17 00:00:00 2001 From: Lorenzo Vagliano Date: Fri, 25 Oct 2024 14:23:38 +0200 Subject: [PATCH] fix: fetched filetype from article data Signed-off-by: Lorenzo Vagliano Also ensured support for different ways to type pdf/a. --- scoap3/articles/tasks.py | 10 +++++++++- scoap3/tasks.py | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scoap3/articles/tasks.py b/scoap3/articles/tasks.py index 097011acf..7f4cdf0d1 100644 --- a/scoap3/articles/tasks.py +++ b/scoap3/articles/tasks.py @@ -57,7 +57,15 @@ def check_required_file_formats(obj): for file in obj.related_files.all(): available_formats.append(file.filetype) - missing_formats = [f for f in required_formats if f not in available_formats] + missing_formats = [] + for f in required_formats: + if f == "pdf/a": + if not any( + variant in available_formats for variant in ["pdf/a", "pdfa", "pdf_a"] + ): + missing_formats.append(f) + elif f not in available_formats: + missing_formats.append(f) if missing_formats: return False, f"Missing required file formats: {', '.join(missing_formats)}." diff --git a/scoap3/tasks.py b/scoap3/tasks.py index c9c09ab3c..77a9a2afb 100644 --- a/scoap3/tasks.py +++ b/scoap3/tasks.py @@ -144,17 +144,27 @@ def _create_article_file(data, article): article_id = article.id filename = file.get("key") file_path = f"files/{article_id}/{filename}" + filetype = file["filetype"] article = Article.objects.get(pk=article_id) - article_file_data = {"article_id": article, "file": file_path} + article_file_data = { + "article_id": article, + "file": file_path, + "filetype": filetype, + } ArticleFile.objects.get_or_create(**article_file_data) for file in data.get("files", {}): article_id = article.id file_path = data["files"][file] + filetype = file if DEFAULT_STORAGE_PATH: file_path = file_path.replace(DEFAULT_STORAGE_PATH, "") article = Article.objects.get(pk=article_id) - article_file_data = {"article_id": article, "file": file_path} + article_file_data = { + "article_id": article, + "file": file_path, + "filetype": filetype, + } ArticleFile.objects.get_or_create(**article_file_data)