Skip to content

Commit

Permalink
fix: fetched filetype from article data
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Vagliano

Also ensured support for different ways to type pdf/a.
  • Loading branch information
Lorenzovagliano committed Oct 25, 2024
1 parent 235b9e7 commit 5eaa09c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion scoap3/articles/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}."
Expand Down
14 changes: 12 additions & 2 deletions scoap3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 5eaa09c

Please sign in to comment.