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

@@ -0,0 +1,35 @@
# Generated by Django 6.0.6 on 2026-08-07 14:26
from django.db import migrations, models
from club.services.images import get_image_dimensions
def backfill_logo_dimensions(apps, schema_editor):
"""Existing sponsors uploaded a logo before these fields existed, so
Sponsor.save()'s new dimension computation never ran for them."""
Sponsor = apps.get_model("club", "Sponsor")
for sponsor in Sponsor.objects.exclude(logo=""):
width, height = get_image_dimensions(sponsor.logo)
Sponsor.objects.filter(pk=sponsor.pk).update(logo_width=width, logo_height=height)
class Migration(migrations.Migration):
dependencies = [
('club', '0019_sponsor'),
]
operations = [
migrations.AddField(
model_name='sponsor',
name='logo_height',
field=models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='logo height'),
),
migrations.AddField(
model_name='sponsor',
name='logo_width',
field=models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='logo width'),
),
migrations.RunPython(backfill_logo_dimensions, migrations.RunPython.noop),
]