From d09e6f3914f43f212c3a1e9292e96b903221c6d7 Mon Sep 17 00:00:00 2001 From: Matthew Northcott Date: Thu, 30 Mar 2023 15:29:23 +1300 Subject: [PATCH] Actually fix the bugs this time --- backend/right_tree/api/signals.py | 6 +++++- backend/right_tree/api/tasks.py | 7 ++++--- docker-compose.production.yaml | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/right_tree/api/signals.py b/backend/right_tree/api/signals.py index 4ea3fea..3ed6abf 100644 --- a/backend/right_tree/api/signals.py +++ b/backend/right_tree/api/signals.py @@ -1,3 +1,4 @@ +from pathlib import Path from shutil import rmtree from django.db.models.signals import post_save, post_delete @@ -10,7 +11,10 @@ from .resource_generation_utils import storage @receiver(post_delete, sender=Export) def delete_export(sender, instance, *args, **kwargs): """Clean up created files on the filesystem when an export is deleted""" - rmtree(storage.path(f"export_{instance.pk}")) + path = storage.path(f"export_{instance.pk}") + + if Path(path).exists(): + rmtree(path) @receiver(post_save, sender=ActivationKeySet) diff --git a/backend/right_tree/api/tasks.py b/backend/right_tree/api/tasks.py index 0caefba..2913611 100644 --- a/backend/right_tree/api/tasks.py +++ b/backend/right_tree/api/tasks.py @@ -14,9 +14,10 @@ from .resource_generation_utils import create_planting_guide_pdf, get_filter_val @shared_task def generate_pdf(questionnaire_id, export_id): q = Questionnaire.objects.get(pk=questionnaire_id) - e = Export.objects.get(pk=export_id) z = q.zone - filename = f"export_{e.pk}/{q.slug}.pdf" + + export = Export.objects.get(pk=export_id) + filename = f"export_{export.pk}/{q.slug}.pdf" try: create_planting_guide_pdf( @@ -35,7 +36,7 @@ def generate_pdf(questionnaire_id, export_id): if not storage.exists(filename): raise FileNotFoundError(f"There was an error creating file: {filename}") - if e.completion >= 1: + if export.completion >= 1: generate_zip.delay(export_id) diff --git a/docker-compose.production.yaml b/docker-compose.production.yaml index 8ea19b4..7d8e24b 100644 --- a/docker-compose.production.yaml +++ b/docker-compose.production.yaml @@ -11,7 +11,6 @@ volumes: x-django: &django image: right-tree env_file: .env - user: "$UID:$GID" restart: always volumes: - righttree-media:/app/right_tree/media -- 2.45.2