Extend the public API: news excerpts/detail, game team logos, sponsor logo dimensions, player licenses

- news: NewsItemOut gains `excerpt` (truncated body); GET /news/{slug}/
  fetches a single item. slug already auto-populates on save, but a
  data migration backfills any pre-existing blank ones.
- games: home_team/away_team change from plain strings to {id, name,
  logo_url} objects -- home links to the actual Team (logo from the
  club's own logo, since teams have none of their own), away links
  to the actual Opponent (which already had a logo field). Breaking
  change for any existing consumer of the old string shape.
- sponsors: SponsorOut gains logo_width/logo_height, computed in
  Sponsor.save() -- Pillow for raster, a bounded regex read of the
  SVG root tag for vector logos (not a full XML parse, since that's
  exposed to entity-expansion attacks on untrusted uploads). A data
  migration backfills dimensions for existing sponsor logos.
- teams: PlayerOut gains `license`, sourced from ClubMembership (not
  Member -- it's per-club, per-season), batched in one query.
This commit is contained in:
2026-08-07 16:33:49 +02:00
parent fc1942575f
commit 7fd42e6047
9 changed files with 354 additions and 29 deletions

View File

@@ -174,6 +174,12 @@ class Sponsor(ClubScopedModel):
# Pillow validation can't read those.
validators=[FileExtensionValidator(allowed_extensions=["png", "jpg", "jpeg", "gif", "webp", "svg"])],
)
# Not user-editable: recomputed from the logo file itself on every save, same reasoning
# NewsPhoto/TeamPhoto don't need this -- FileField (not ImageField) means Django never
# populates width/height on its own. The public API exposes these so a consumer can lay
# out a sponsor strip without waiting on the image to load.
logo_width = models.PositiveIntegerField(_("logo width"), null=True, blank=True, editable=False)
logo_height = models.PositiveIntegerField(_("logo height"), null=True, blank=True, editable=False)
url = models.URLField(_("URL"), blank=True, help_text=_("The sponsor's own website, if they have one."))
start_date = models.DateField(_("start date"))
@@ -191,6 +197,14 @@ class Sponsor(ClubScopedModel):
if self.end_date is not None and self.start_date is not None and self.end_date < self.start_date:
raise ValidationError({"end_date": _("End date can't be before the start date.")})
def save(self, *args, **kwargs):
# Deferred: club.services (via its __init__) imports back from club.models, so a
# module-level import here would be circular.
from club.services.images import get_image_dimensions
self.logo_width, self.logo_height = get_image_dimensions(self.logo) if self.logo else (None, None)
super().save(*args, **kwargs)
class Season(ClubScopedModel):
start_date = models.DateField(_("start date"))