From 6ed81a49d1705610e13985e9ebc9a1ce7bd4800e Mon Sep 17 00:00:00 2001 From: Lova Andriarimalala <43842786+Xpirix@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:35:48 +0300 Subject: [PATCH] Handle missing resource files to prevent FileNotFoundError (#427) --- qgis-app/base/views/processing_view.py | 5 ++++- qgis-app/templates/base/detail.html | 8 +++++++- qgis-app/templates/base/list.html | 4 +++- qgis-app/templates/base/list_galery.html | 9 ++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/qgis-app/base/views/processing_view.py b/qgis-app/base/views/processing_view.py index 3b1352ff..442d9553 100644 --- a/qgis-app/base/views/processing_view.py +++ b/qgis-app/base/views/processing_view.py @@ -1,5 +1,5 @@ import logging - +from os.path import exists from base.forms.processing_forms import ResourceBaseReviewForm from base.license import zipped_with_license from django.conf import settings @@ -29,6 +29,7 @@ ) from django.views.generic.base import ContextMixin from django.utils.encoding import escape_uri_path +from django.http import Http404 GROUP_NAME = "Style Managers" @@ -468,6 +469,8 @@ class ResourceBaseDownload(ResourceBaseContextMixin, View): def get(self, request, *args, **kwargs): object = get_object_or_404(self.model, pk=self.kwargs["pk"]) + if not exists(object.file.path): + raise Http404 if not object.approved: if not check_resources_access(self.request.user, object): context = super(ResourceBaseDownload, self).get_context_data() diff --git a/qgis-app/templates/base/detail.html b/qgis-app/templates/base/detail.html index 745c58dd..d9571c23 100644 --- a/qgis-app/templates/base/detail.html +++ b/qgis-app/templates/base/detail.html @@ -19,9 +19,11 @@