feat: improve admin and add demo data command

This commit is contained in:
2026-04-29 12:06:55 +02:00
parent 2b71b7a418
commit d1801b8c9b
8 changed files with 209 additions and 3 deletions

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,126 @@
import sys
from datetime import datetime
from datetime import timedelta
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
from shows.models import Performance, Show, Venue
class Command(BaseCommand):
help = "Create or update local demo data for AzioneLab."
def handle(self, *args, **options):
if not settings.DEBUG and "test" not in sys.argv:
raise CommandError("seed_demo_data is available only in local or test environments.")
today = timezone.localdate()
venues = [
{
"name": "AzioneLab Theatre",
"slug": "azionelab-theatre",
"address": "Via Example 1",
"city": "Rome",
"notes": "Main house for evening performances.",
},
{
"name": "Studio Nuovo",
"slug": "studio-nuovo",
"address": "Via Example 22",
"city": "Rome",
"notes": "Smaller venue for workshops and matinees.",
},
]
shows = [
{
"title": "Open Stage",
"slug": "open-stage",
"summary": "A contemporary theatre performance.",
"description": "A compact demo production for manual backend testing.",
"poster_image": "",
"is_published": True,
},
{
"title": "City Echoes",
"slug": "city-echoes",
"summary": "An ensemble piece set across modern Rome.",
"description": "A second published show with a different venue mix.",
"poster_image": "",
"is_published": True,
},
]
venue_map = {}
show_map = {}
for venue_data in venues:
venue, _ = Venue.objects.update_or_create(
slug=venue_data["slug"],
defaults=venue_data,
)
venue_map[venue.slug] = venue
for show_data in shows:
show, _ = Show.objects.update_or_create(
slug=show_data["slug"],
defaults=show_data,
)
show_map[show.slug] = show
performances = [
{
"show": show_map["open-stage"],
"venue": venue_map["azionelab-theatre"],
"starts_at": self._performance_starts_at(today + timedelta(days=7), hour=20, minute=30),
"room_capacity": 120,
"manually_occupied_seats": 8,
"additional_seats": 4,
"is_booking_enabled": True,
},
{
"show": show_map["open-stage"],
"venue": venue_map["studio-nuovo"],
"starts_at": self._performance_starts_at(today + timedelta(days=14), hour=18, minute=0),
"room_capacity": 60,
"manually_occupied_seats": 2,
"additional_seats": 0,
"is_booking_enabled": True,
},
{
"show": show_map["city-echoes"],
"venue": venue_map["azionelab-theatre"],
"starts_at": self._performance_starts_at(today + timedelta(days=21), hour=20, minute=30),
"room_capacity": 140,
"manually_occupied_seats": 12,
"additional_seats": 6,
"is_booking_enabled": True,
},
]
created_or_updated = 0
for performance_data in performances:
_, _created = Performance.objects.update_or_create(
show=performance_data["show"],
venue=performance_data["venue"],
starts_at=performance_data["starts_at"],
defaults={
"room_capacity": performance_data["room_capacity"],
"manually_occupied_seats": performance_data["manually_occupied_seats"],
"additional_seats": performance_data["additional_seats"],
"is_booking_enabled": performance_data["is_booking_enabled"],
},
)
created_or_updated += 1
self.stdout.write(
self.style.SUCCESS(
f"Demo data ready: {len(show_map)} shows, {len(venue_map)} venues, {created_or_updated} performances."
)
)
def _performance_starts_at(self, day, *, hour, minute):
naive = datetime.combine(day, datetime.min.time()).replace(hour=hour, minute=minute)
return timezone.make_aware(naive, timezone.get_current_timezone())