inital commit
This commit is contained in:
1
builder/management/commands/__init__.py
Normal file
1
builder/management/commands/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
49
builder/management/commands/seed_templates.py
Normal file
49
builder/management/commands/seed_templates.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from builder.models import TemplateOption
|
||||
from builder.template_registry import discover_client_templates
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Seed template options from templates/template_* folders and site_catalog/templates.json"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
root = Path(__file__).resolve().parents[4]
|
||||
catalog_path = root / "site_catalog" / "templates.json"
|
||||
|
||||
discovered = {item["slug"]: item for item in discover_client_templates()}
|
||||
catalog_items: dict[str, dict] = {}
|
||||
|
||||
if catalog_path.exists():
|
||||
for item in json.loads(catalog_path.read_text(encoding="utf-8")):
|
||||
catalog_items[item["slug"]] = item
|
||||
|
||||
merged_slugs = set(discovered) | set(catalog_items)
|
||||
count = 0
|
||||
|
||||
for slug in sorted(merged_slugs):
|
||||
discovered_item = discovered.get(slug, {})
|
||||
catalog_item = catalog_items.get(slug, {})
|
||||
merged = {**discovered_item, **catalog_item}
|
||||
if not merged.get("source_folder"):
|
||||
self.stdout.write(self.style.WARNING(f"Skipping {slug}: no source_folder."))
|
||||
continue
|
||||
|
||||
TemplateOption.objects.update_or_create(
|
||||
slug=slug,
|
||||
defaults={
|
||||
"name": merged.get("name", slug),
|
||||
"description": merged.get("description", ""),
|
||||
"supports_basic": merged.get("supports_basic", True),
|
||||
"supports_django": merged.get("supports_django", True),
|
||||
"source_folder": merged["source_folder"],
|
||||
"is_active": merged.get("is_active", True),
|
||||
},
|
||||
)
|
||||
count += 1
|
||||
|
||||
TemplateOption.objects.exclude(slug__in=merged_slugs).update(is_active=False)
|
||||
self.stdout.write(self.style.SUCCESS(f"Seeded {count} template option(s)."))
|
||||
Reference in New Issue
Block a user