Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ <h3 class="widget-title">Job Board Sponsors</h3>

{% for package, placement_info in sponsorships_by_package.items %}
{% if placement_info.sponsorships %}
<div title="{{ package }} Sponsors" align="center">
<div title="{{ package }} Sponsors" align="center" style="margin-bottom: 3em;">
{% with dimension=placement_info.logo_dimension %}

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

<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax({{ dimension }}px, 0fr)); grid-template-rows: repeat(1, minmax({{ dimension }}px, 0fr)); align-items: center; justify-content: center;">
<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax({{ dimension }}px, 1fr)); align-items: center; justify-content: center;">
{% for sponsorship in placement_info.sponsorships %}
<div id="{{ sponsorship.sponsor.slug }}" data-internal-year={{ sponsorship.year }}>
<div
Expand Down
2 changes: 1 addition & 1 deletion apps/sponsors/templatetags/sponsors.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def ideal_size(image, ideal_dimension):
ideal_dimension = int(ideal_dimension)
try:
w, h = image.width, image.height
except FileNotFoundError:
except (FileNotFoundError, ValueError):
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ideal_size filter now catches ValueError in addition to FileNotFoundError, but there's no test coverage for this filter. Consider adding tests to verify the error handling behavior, especially for cases where the image file is missing or has invalid dimensions that could raise ValueError.

Copilot uses AI. Check for mistakes.
# local dev doesn't have all images if DB is a copy from prod environment
# this is just a fallback to return ideal_dimension instead
w, h = ideal_dimension, ideal_dimension
Expand Down
31 changes: 31 additions & 0 deletions apps/sponsors/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
benefit_quantity_for_package,
full_sponsorship,
list_sponsors,
ideal_size,
)


Expand Down Expand Up @@ -88,3 +89,33 @@ def test_display_name_for_display_from_benefit(self, mocked_name_for_display):

self.assertEqual(name, "Modified name")
mocked_name_for_display.assert_called_once_with(package=package)


class IdealSizeTemplateTagTests(TestCase):
def test_ideal_size_scales_properly(self):
class MockImage:
width = 400
height = 200

size = ideal_size(MockImage(), 200)
# int(400 * sqrt(20000 / 80000)) = int(400 * 0.5) = 200
self.assertEqual(size, 200)

def test_ideal_size_handles_file_not_found(self):
class MockImageWithoutFile:
@property
def width(self):
raise FileNotFoundError()

size = ideal_size(MockImageWithoutFile(), 300)
self.assertEqual(size, 173)

def test_ideal_size_handles_value_error(self):
class MockImageWithoutFileValue:
@property
def width(self):
msg = "The 'web_logo' attribute has no file associated with it."
raise ValueError(msg)

size = ideal_size(MockImageWithoutFileValue(), 250)
self.assertEqual(size, 158)
Loading
Loading