Skip to content

Commit ba31185

Browse files
authored
fix svg load (#2969)
1 parent e139fc0 commit ba31185

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

apps/sponsors/admin.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -736,24 +736,35 @@ def get_sponsor_landing_page_url(self, obj):
736736
@admin.display(description="Web Logo")
737737
def get_sponsor_web_logo(self, obj):
738738
"""Render and return the sponsor's web logo as a thumbnail image."""
739-
html = "{% load thumbnail %}{% thumbnail sponsor.web_logo '150x150' format='PNG' quality=100 as im %}<img src='{{ im.url}}'/>{% endthumbnail %}"
739+
img = obj.sponsor.web_logo
740+
if not img:
741+
return "---"
742+
if img.name and img.name.lower().endswith(".svg"):
743+
return format_html(
744+
'<img src="{}" style="max-width:150px;max-height:150px"/>',
745+
img.url,
746+
)
747+
html = "{% load thumbnail %}{% thumbnail img '150x150' format='PNG' quality=100 as im %}<img src='{{ im.url}}'/>{% endthumbnail %}"
740748
template = Template(html)
741-
context = Context({"sponsor": obj.sponsor})
742-
html = template.render(context)
743-
return mark_safe(html) # noqa: S308
749+
context = Context({"img": img})
750+
return mark_safe(template.render(context)) # noqa: S308
744751

745752
@admin.display(description="Print Logo")
746753
def get_sponsor_print_logo(self, obj):
747754
"""Render and return the sponsor's print logo as a thumbnail image."""
748755
img = obj.sponsor.print_logo
749-
html = "---"
750-
if img:
751-
template = Template(
752-
"{% load thumbnail %}{% thumbnail img '150x150' format='PNG' quality=100 as im %}<img src='{{ im.url}}'/>{% endthumbnail %}"
756+
if not img:
757+
return "---"
758+
if img.name and img.name.lower().endswith(".svg"):
759+
return format_html(
760+
'<img src="{}" style="max-width:150px;max-height:150px"/>',
761+
img.url,
753762
)
754-
context = Context({"img": img})
755-
html = mark_safe(template.render(context)) # noqa: S308
756-
return html
763+
template = Template(
764+
"{% load thumbnail %}{% thumbnail img '150x150' format='PNG' quality=100 as im %}<img src='{{ im.url}}'/>{% endthumbnail %}"
765+
)
766+
context = Context({"img": img})
767+
return mark_safe(template.render(context)) # noqa: S308
757768

758769
@admin.display(description="Primary Phone")
759770
def get_sponsor_primary_phone(self, obj):

apps/sponsors/templates/sponsors/partials/sponsors-list.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ <h2 class="widget-title" style="text-align: center;">Sponsors</h2>
1010
<p style="text-align: center;">Visionary sponsors help to host Python downloads.</p>
1111
<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax(150px, 0fr)); align-items: center; justify-content: center; margin-top: 1.5em;">
1212
{% for sponsorship in sponsorships %}
13-
{% thumbnail sponsorship.sponsor.web_logo "x150" format="PNG" quality=100 as im %}
1413
<div style="text-align: center;">
1514
<a href="{{ sponsorship.sponsor.landing_page_url }}" rel="sponsored noopener" target="_blank" style="border-bottom: 0;">
15+
{% if sponsorship.sponsor.web_logo.name|lower|slice:"-4:" == ".svg" %}
16+
<img src="{{ sponsorship.sponsor.web_logo.url }}" alt="{{ sponsorship.sponsor.name }} logo" style="max-height:150px;max-width:150px;height:auto;width:auto;">
17+
{% else %}
18+
{% thumbnail sponsorship.sponsor.web_logo "x150" format="PNG" quality=100 as im %}
1619
<img src="{{ im.url }}" alt="{{ sponsorship.sponsor.name }} logo" style="max-height:150px;max-width:150px;height:auto;width:auto;">
20+
{% endthumbnail %}
21+
{% endif %}
1722
</a>
1823
<p style="margin-top: 0.5em; margin-bottom: 0; font-size: 0.875em; color: #4d4d4d;">{{ sponsorship.sponsor.name }}</p>
1924
</div>
20-
{% endthumbnail %}
2125
{% endfor %}
2226
</div>
2327
{% endcache CACHED_DOWNLOAD_SPONSORS_LIST %}
@@ -28,11 +32,15 @@ <h2 class="widget-title" style="text-align: center;">Sponsors</h2>
2832
<h3 class="widget-title">Job Board Sponsors</h3>
2933
<div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(auto-fit, minmax(100px, 0fr)); grid-template-rows: repeat(1, minmax(50px, 0fr)); align-items: center; justify-content: center; margin-top: 1em;">
3034
{% for sponsorship in sponsorships %}
31-
{% thumbnail sponsorship.sponsor.web_logo "x100" format="PNG" quality=100 as im %}
3235
<div>
36+
{% if sponsorship.sponsor.web_logo.name|lower|slice:"-4:" == ".svg" %}
37+
<img src="{{ sponsorship.sponsor.web_logo.url }}" alt="{{ sponsorship.sponsor.name }} logo" style="max-height:100px;max-width:100px;height:auto;width:auto;">
38+
{% else %}
39+
{% thumbnail sponsorship.sponsor.web_logo "x100" format="PNG" quality=100 as im %}
3340
<img src="{{ im.url }}" alt="{{ sponsorship.sponsor.name }} logo" style="max-height:100px;max-width:100px;height:auto;width:auto;">
41+
{% endthumbnail %}
42+
{% endif %}
3443
</div>
35-
{% endthumbnail %}
3644
{% endfor %}
3745
</div>
3846
{% endcache CACHED_JOBS_SPONSORS_LIST %}

0 commit comments

Comments
 (0)