Fetch raw files from Forgejo, sanitize markdown to HTML, and show them on space detail. Ship a public demo fixture path and seed_demo_space command.
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""Seed a demo Space bound to the in-repo Forgejo fixture path (public raw)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from coulomb_social.apps.spaces.models import Space
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = (
|
|
"Create or update the demo space (tenant from DEFAULT_TENANT_ID) bound to "
|
|
"coulomb/coulomb-social docs/space-fixtures/demo/pages for T04 smoke."
|
|
)
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("--slug", default="demo")
|
|
parser.add_argument("--title", default="Demo space")
|
|
parser.add_argument(
|
|
"--tenant",
|
|
default="",
|
|
help="Defaults to DEFAULT_TENANT_ID",
|
|
)
|
|
parser.add_argument(
|
|
"--owner",
|
|
default="coulomb",
|
|
help="Forgejo owner",
|
|
)
|
|
parser.add_argument(
|
|
"--repo",
|
|
default="coulomb-social",
|
|
help="Forgejo repo containing fixture markdown",
|
|
)
|
|
parser.add_argument(
|
|
"--content-root",
|
|
default="docs/space-fixtures/demo/pages",
|
|
)
|
|
parser.add_argument("--branch", default="main")
|
|
|
|
def handle(self, *args, **options):
|
|
tenant = options["tenant"] or settings.DEFAULT_TENANT_ID
|
|
slug = options["slug"]
|
|
space, created = Space.objects.update_or_create(
|
|
tenant_id=tenant,
|
|
slug=slug,
|
|
defaults={
|
|
"title": options["title"],
|
|
"description": "Seeded demo space with markdown from Forgejo (CSOC-WP-0004-T04).",
|
|
"forgejo_owner": options["owner"],
|
|
"forgejo_repo": options["repo"],
|
|
"default_branch": options["branch"],
|
|
"content_root": options["content_root"],
|
|
"is_active": True,
|
|
},
|
|
)
|
|
action = "Created" if created else "Updated"
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f"{action} space {space.slug} tenant={space.tenant_id} "
|
|
f"→ {space.forgejo_owner}/{space.forgejo_repo} "
|
|
f"({space.content_root}/index.md @ {space.default_branch})"
|
|
)
|
|
)
|