|
|
@ -11,25 +11,35 @@ class Command(BaseCommand):
|
|
|
|
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
|
"--force",
|
|
|
|
"-f", "--force", action="store_true", help="Always overwrite content"
|
|
|
|
action="store_true",
|
|
|
|
|
|
|
|
help="Always overwrite content",
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument("pages", help="Specify which pages to import", nargs="*")
|
|
|
|
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
content_path = Path(__file__).resolve().parent.parent.parent / "default_content"
|
|
|
|
content_path = Path(__file__).resolve().parent.parent.parent / "default_content"
|
|
|
|
for file in content_path.iterdir():
|
|
|
|
for file in content_path.iterdir():
|
|
|
|
|
|
|
|
if (pages := options["pages"]) and file.stem not in pages:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
slug = file.stem
|
|
|
|
slug = file.stem
|
|
|
|
p, created = Page.objects.get_or_create(url=slug)
|
|
|
|
p, created = Page.objects.get_or_create(url=slug)
|
|
|
|
if (not created) and (not options["force"]):
|
|
|
|
if (not created) and (not options["force"]):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
soup = BeautifulSoup(file.read_text(), "html.parser")
|
|
|
|
soup = BeautifulSoup(file.read_text(), "html.parser")
|
|
|
|
|
|
|
|
|
|
|
|
if soup.title:
|
|
|
|
if soup.title:
|
|
|
|
p.title = soup.title.string
|
|
|
|
p.title = soup.title.string
|
|
|
|
soup.title.decompose()
|
|
|
|
soup.title.decompose()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
p.title = slug.title()
|
|
|
|
p.title = slug.title()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if visible := soup.find("meta", attrs={"name": "visible"}):
|
|
|
|
|
|
|
|
p.visible = "content" not in visible.attrs or visible.attrs[
|
|
|
|
|
|
|
|
"content"
|
|
|
|
|
|
|
|
].lower() in ("1", "true", "yes")
|
|
|
|
|
|
|
|
visible.decompose()
|
|
|
|
|
|
|
|
|
|
|
|
p.content = str(soup).strip()
|
|
|
|
p.content = str(soup).strip()
|
|
|
|
p.save()
|
|
|
|
p.save()
|
|
|
|
print(f'created new page "{p.title}" for slug {slug}')
|
|
|
|
print(f'created new page "{p.title}" for slug {slug}')
|
|
|
|