move html import into subcommand
This commit is contained in:
parent
2b5ed73f9b
commit
a047862be5
|
@ -9,6 +9,7 @@ case "$ROLE" in
|
|||
rm -rf static/*
|
||||
python manage.py collectstatic
|
||||
python manage.py migrate
|
||||
python manage.py importhtml
|
||||
gunicorn shiftregister.wsgi -b 0.0.0.0:8000 "$@"
|
||||
;;
|
||||
worker)
|
||||
|
|
|
@ -1,29 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
from pathlib import Path
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
|
||||
def read_pages(sender, **kwargs):
|
||||
from .models import Page
|
||||
|
||||
print("pages init")
|
||||
content_path = Path(__file__).resolve().parent / "default_content"
|
||||
for file in content_path.iterdir():
|
||||
slug = file.stem
|
||||
p, created = Page.objects.get_or_create(url=slug)
|
||||
if not created:
|
||||
continue
|
||||
p.content = file.read_text()
|
||||
p.title = slug
|
||||
p.save()
|
||||
print(f"created new page for slug {slug}")
|
||||
|
||||
|
||||
class PagesConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shiftregister.pages"
|
||||
|
||||
def ready(self):
|
||||
# we use thios signal so our code is not called before the schema is migrated
|
||||
# and not during makemigrations/migrate
|
||||
post_migrate.connect(read_pages, sender=self)
|
||||
|
|
|
@ -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