tl/scenes/management/commands/seed_demo.py

38 lines
1.4 KiB
Python
Raw Normal View History

"""Create a demo Project owned by `admin`, with the bundled OTIO attached."""
from pathlib import Path
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.management.base import BaseCommand
from scenes.models import Project
PUBLIC = settings.BASE_DIR / "tl" / "resources" / "public"
OTIO = PUBLIC / "one_two_three.otio"
CLIP = PUBLIC / "challengers_480p.mp4"
class Command(BaseCommand):
help = "Seed the demo Challengers project from the bundled OTIO + clip."
def handle(self, *args, **opts):
User = get_user_model()
owner = User.objects.filter(username="admin").first()
if owner is None:
self.stderr.write("no 'admin' user — run createsuperuser first")
return
project, created = Project.objects.get_or_create(
owner=owner, name="Challengers", defaults={"scene": {}})
if OTIO.exists() and not project.otio:
with OTIO.open("rb") as fh:
project.otio.save(OTIO.name, File(fh), save=True)
if CLIP.exists() and not project.clip:
with CLIP.open("rb") as fh:
project.clip.save(CLIP.name, File(fh), save=True)
verb = "created" if created else "exists"
self.stdout.write(f"project #{project.pk} {verb}: {project.name} "
f"(otio={bool(project.otio)} clip={bool(project.clip)})")