move html import into subcommand
parent
2b5ed73f9b
commit
a047862be5
@ -0,0 +1,26 @@
|
|||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from ...models import Page
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "add missing cms files to database"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--force",
|
||||||
|
action="store_true",
|
||||||
|
help="Always overwrite content",
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
content_path = Path(__file__).resolve().parent.parent.parent / "default_content"
|
||||||
|
for file in content_path.iterdir():
|
||||||
|
slug = file.stem
|
||||||
|
p, created = Page.objects.get_or_create(url=slug)
|
||||||
|
if (not created) and (not options["force"]):
|
||||||
|
continue
|
||||||
|
p.content = file.read_text()
|
||||||
|
p.title = slug
|
||||||
|
p.save()
|
||||||
|
print(f"created new page for slug {slug}")
|
Loading…
Reference in New Issue