Skip to content

Commit f961a3d

Browse files
committed
Fix sponsor logo collision and refine CSS grid (Issue #2887)
1 parent e5eb15f commit f961a3d

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% cache 86400 CACHED_DOWNLOAD_SPONSORS_LIST %}
99
<h2 class="widget-title" style="text-align: center;">Sponsors</h2>
1010
<p style="text-align: center;">Visionary sponsors help to host Python downloads.</p>
11-
<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: center; justify-content: center; margin-top: 1.5em;">
11+
<div style="display: grid; gap: 2em; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: center; justify-content: center; margin-top: 1.5em;">
1212
{% for sponsorship in sponsorships %}
1313
{% thumbnail sponsorship.sponsor.web_logo "x150" format="PNG" quality=100 as im %}
1414
<div style="text-align: center;">
@@ -26,7 +26,7 @@ <h2 class="widget-title" style="text-align: center;">Sponsors</h2>
2626
{% comment %}cache for 1 day{% endcomment %}
2727
{% cache 86400 CACHED_JOBS_SPONSORS_LIST %}
2828
<h3 class="widget-title">Job Board Sponsors</h3>
29-
<div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); align-items: center; justify-content: center; margin-top: 1em;">
29+
<div style="display: grid; gap: 1em; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); align-items: center; justify-content: center; margin-top: 1em;">
3030
{% for sponsorship in sponsorships %}
3131
{% thumbnail sponsorship.sponsor.web_logo "x100" format="PNG" quality=100 as im %}
3232
<div>
@@ -43,14 +43,14 @@ <h3 class="widget-title">Job Board Sponsors</h3>
4343

4444
{% for package, placement_info in sponsorships_by_package.items %}
4545
{% if placement_info.sponsorships %}
46-
<div title="{{ package }} Sponsors" align="center" style="margin-bottom: 3em;">
46+
<div title="{{ package }} Sponsors" align="center" style="{% if not forloop.last %}margin-bottom: 3em;{% endif %}">
4747
{% with dimension=placement_info.logo_dimension %}
4848

4949
<h1 style="font-size: {% if forloop.first %}350%{% else %}300%{% endif %}">{{ placement_info.label }} Sponsors</h1>
5050

51-
<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax({{ dimension }}px, 1fr)); align-items: center; justify-content: center;">
51+
<div style="display: grid; gap: 2em; grid-template-columns: repeat(auto-fit, minmax({{ dimension }}px, 1fr)); align-items: center; justify-content: center;">
5252
{% for sponsorship in placement_info.sponsorships %}
53-
<div id="{{ sponsorship.sponsor.slug }}" data-internal-year={{ sponsorship.year }}>
53+
<div id="{{ sponsorship.sponsor.slug }}" data-internal-year={{ sponsorship.year }} style="overflow: hidden;">
5454
<div
5555
data-ea-publisher="psf"
5656
data-ea-type="psf-image-only"

apps/sponsors/templatetags/sponsors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ def ideal_size(image, ideal_dimension):
8383
ideal_dimension = int(ideal_dimension)
8484
try:
8585
w, h = image.width, image.height
86-
except (FileNotFoundError, ValueError):
86+
except (FileNotFoundError, ValueError) as e:
8787
# local dev doesn't have all images if DB is a copy from prod environment
88-
# this is just a fallback to return ideal_dimension instead
88+
# in that case, we return a fallback size to avoid 500 errors.
89+
# we only catch the specific ValueError raised by Django when a file is missing.
90+
if isinstance(e, ValueError) and "no file associated with it" not in str(e):
91+
raise
8992
w, h = ideal_dimension, ideal_dimension
9093

9194
return int(w * math.sqrt((100 * ideal_dimension) / (w * h)))

apps/sponsors/tests/test_templatetags.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
benefit_name_for_display,
99
benefit_quantity_for_package,
1010
full_sponsorship,
11-
list_sponsors,
1211
ideal_size,
12+
list_sponsors,
1313
)
1414

1515

@@ -105,7 +105,7 @@ def test_ideal_size_handles_file_not_found(self):
105105
class MockImageWithoutFile:
106106
@property
107107
def width(self):
108-
raise FileNotFoundError()
108+
raise FileNotFoundError
109109

110110
size = ideal_size(MockImageWithoutFile(), 300)
111111
self.assertEqual(size, 173)
@@ -119,3 +119,13 @@ def width(self):
119119

120120
size = ideal_size(MockImageWithoutFileValue(), 250)
121121
self.assertEqual(size, 158)
122+
123+
def test_ideal_size_raises_other_value_errors(self):
124+
class MockImageWithOtherValueError:
125+
@property
126+
def width(self):
127+
msg = "Other error"
128+
raise ValueError(msg)
129+
130+
with self.assertRaises(ValueError):
131+
ideal_size(MockImageWithOtherValueError(), 250)

0 commit comments

Comments
 (0)