Fix mismatched fallback text colour on the initials badge/button

The initials badge and reset button hardcoded two independent
fallback literals -- a background (#ec4899 / #0ea5e9) and a text
colour (#ffffff) -- that were only ever chosen together for a club's
own colour via Club._content_color_for. #ffffff on #ec4899 or
#0ea5e9 actually contrasts worse than black by the same WCAG formula
the app already uses elsewhere (verified: 6.4:1 vs 3.3:1, and 7.6:1
vs 2.8:1). Added a contrast_color filter so the text colour is always
derived from whatever background hex is actually in play -- real
club colour or fallback alike -- instead of a second, independently
guessed literal that can silently drift out of sync with the first.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-12 09:50:07 +02:00
parent 9901a90266
commit 67841491a6
7 changed files with 72 additions and 4 deletions

View File

@@ -1516,6 +1516,21 @@ class ParentClaimViewTests(ManagementTestBase):
[reset_path] = [line for line in sent.body.splitlines() if "/accounts/password/reset/key/" in line]
self.assertIn(reset_path.strip(), html_body)
def test_the_initials_badge_text_contrasts_against_the_fallback_colour(self):
# self.club has no secondary_color set, so the badge falls back to
# #ec4899 -- white text on that (the old hardcoded default) reads
# far worse than black (contrast_color("#ec4899") == "#000000"), see
# club/templatetags/club_email.py::contrast_color.
self.submit()
claim = ParentClaim.objects.get(club=self.club)
self.client.force_login(self.admin_user)
self.club_post("parent_claim_approve", {"child": str(self.child.pk)}, claim.pk)
[(html_body, _mimetype)] = mail.outbox[0].alternatives
self.assertIn("background-color:#ec4899", html_body)
self.assertIn("color:#000000", html_body)
def test_the_email_mentions_the_clubs_contact_email_when_set(self):
self.club.contact_email = "info@ajax-united.example.com"
self.club.save(update_fields=["contact_email"])