Skip to content

Commit

Permalink
Handle invalid icon in plugins list and details
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Jun 6, 2024
1 parent 75a5de1 commit b792327
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion qgis-app/plugins/templates/plugins/plugin_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h2>
<div class="span12">
{% endif %}
<h2>{{ object.name }}
{% if object.icon and object.icon.file %}
{% if object.icon and object.icon.file and object.icon|is_image_valid %}
{% with image_extension=object.icon.name|file_extension %}
{% if image_extension == 'svg' %}
<img class="pull-right plugin-icon" alt="{% trans "Plugin icon" %}" src="{{ object.icon.url }}" width="24" height="24" />
Expand All @@ -154,6 +154,8 @@ <h2>{{ object.name }}
{% endthumbnail %}
{% endif %}
{% endwith %}
{% else %}
<img height="32" width="32" class="pull-right plugin-icon" src="{% static "images/qgis-icon-32x32.png" %}" alt="{% trans "Plugin icon" %}" />
{% endif %}
</h2>
<div>
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/plugins/templates/plugins/plugin_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
{% for object in object_list %}
<tr class="pmain {% if object.deprecated %} error deprecated{% endif %}" id="pmain{{object.pk}}">
<td><a title="{% if object.deprecated %} [DEPRECATED] {% endif %}{% trans "Click here for plugin details" %}" href="{% url "plugin_detail" object.package_name %}">
{% if object.icon and object.icon.file %}
{% if object.icon and object.icon.file and object.icon|is_image_valid %}
{% with image_extension=object.icon.name|file_extension %}
{% if image_extension == 'svg' %}
<img class="pull-right plugin-icon" alt="{% trans "Plugin icon" %}" src="{{ object.icon.url }}" width="24" height="24" />
Expand Down
14 changes: 13 additions & 1 deletion qgis-app/plugins/templatetags/plugin_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import template
from PIL import Image, UnidentifiedImageError

register = template.Library()

Expand Down Expand Up @@ -27,4 +28,15 @@ def plugin_title(context):

@register.filter
def file_extension(value):
return value.split('.')[-1].lower()
return value.split('.')[-1].lower()

@register.filter
def is_image_valid(image):
if not image:
return False
try:
img = Image.open(image.path)
img.verify()
return True
except (FileNotFoundError, UnidentifiedImageError):
return False

0 comments on commit b792327

Please sign in to comment.