Skip to content

Commit

Permalink
Handle missing resource files to prevent FileNotFoundError (qgis#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix authored Jun 17, 2024
1 parent 0635b62 commit 6ed81a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion qgis-app/base/views/processing_view.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion qgis-app/templates/base/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ <h3 class="style-title">{{ object_detail.name }}</h3>
<div class="row">
<div class="span4 mb-5 view-resource">
<div class="style-polaroid">
{% if object_detail.thumbnail_image and object_detail.thumbnail_image.file %}
{% thumbnail object_detail.thumbnail_image "420x420" format="PNG" as im %}
<img class="image-resource" alt="{% trans "image" %}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}" />
{% endthumbnail %}
{% endif %}
{% if is_3d_model %}
{% include "base/includes/wavefront/detail_3dviewer.html" %}
{% else %}
Expand All @@ -34,7 +36,11 @@ <h3 class="style-title">{{ object_detail.name }}</h3>
<dt>{{ resource_name }} File</dt>
<dd>
<div>
<a class="btn btn-primary btn-mini" href="{% url url_download object_detail.id %}" title="{% trans "Download" %}"><i class="icon-download-alt"></i> Download</a>
{% if object_detail.file and object_detail.file.file %}
<a class="btn btn-primary btn-mini" href="{% url url_download object_detail.id %}" title="{% trans "Download" %}"><i class="icon-download-alt"></i> Download</a>
{% else %}
<em>File missing: The resource file couldn't be located.</em>
{% endif %}
</div>
</dd>
</dl>
Expand Down
4 changes: 3 additions & 1 deletion qgis-app/templates/base/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All" %} {{ resource_name }}s{% en
<a class="btn btn-primary btn-mini" href="{% url url_update object.id %}" title="{% trans "Edit" %}"><i class="icon-pencil icon-white"></i></a>&nbsp
<a class="btn btn-danger btn-mini delete" href="{% url url_delete object.id %}" title="{% trans "Delete" %}"><i class="icon-remove icon-white"></i></a>&nbsp
{% endif %}
<a class="btn btn-primary btn-mini pull-right" href="{% url url_download object.id %}" title="{% trans "Download" %}"><i class="icon-download-alt"></i></a>
{% if object.file and object.file.file %}
<a class="btn btn-primary btn-mini pull-right" href="{% url url_download object.id %}" title="{% trans "Download" %}"><i class="icon-download-alt"></i></a>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
9 changes: 8 additions & 1 deletion qgis-app/templates/base/list_galery.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All" %} {{ resource_name }}s{% en
</a>
</div>
<div class="image-info">
<a class="btn btn-mini btn-download pull-right" href="{% url url_download object.id %}" title="{% trans "Download" %}"><i class="icon-download-alt"></i></a>
{% if object.file and object.file.file %}
<a
class="btn btn-mini btn-download pull-right"
href="{% url url_download object.id %}"
title="{% trans "Download" %}">
<i class="icon-download-alt"></i>
</a>
{% endif %}
<a href="{% url url_detail pk=object.id %}">
<h4>
{{ object.name}}
Expand Down

0 comments on commit 6ed81a4

Please sign in to comment.