Files
RosterChief/news/migrations/0002_backfill_slugs.py
Bernard Siebens 7fd42e6047 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.
2026-08-07 16:33:49 +02:00

24 lines
758 B
Python

from django.db import migrations
from rosterchief.base import unique_slugify
def backfill_slugs(apps, schema_editor):
"""News.save() already auto-populates a blank slug (rosterchief.base.
ClubScopedModel.save), but that only fires on save() -- rows created
before the slug field existed, or via bulk_create, never got one."""
News = apps.get_model("news", "News")
for item in News.objects.filter(slug=""):
item.slug = unique_slugify(item, item.title, scope={"club_id": item.club_id})
item.save(update_fields=["slug"])
class Migration(migrations.Migration):
dependencies = [
("news", "0001_initial"),
]
operations = [
migrations.RunPython(backfill_slugs, migrations.RunPython.noop),
]