2025.12.27 13:33:05 (cachyos.cmoser.eu)
This commit is contained in:
@@ -25,13 +25,12 @@ class Command(BaseCommand):
|
|||||||
if not options['file']:
|
if not options['file']:
|
||||||
raise CommandError("No file to import specified")
|
raise CommandError("No file to import specified")
|
||||||
|
|
||||||
|
filename = Path(options['file'][0]).resolve()
|
||||||
|
print(f"Importing from {filename} ...")
|
||||||
|
|
||||||
file = Path(options['file'][0]).resolve()
|
if not filename.exists():
|
||||||
print(f"Importing from {file} ...")
|
|
||||||
|
|
||||||
if not file.exists():
|
|
||||||
raise CommandError("File does not exist!")
|
raise CommandError("File does not exist!")
|
||||||
if not file.is_file():
|
if not filename.is_file():
|
||||||
raise CommandError("Not a file!")
|
raise CommandError("Not a file!")
|
||||||
|
|
||||||
username = options['username']
|
username = options['username']
|
||||||
@@ -50,8 +49,8 @@ class Command(BaseCommand):
|
|||||||
except UserModel.DoesNotExist:
|
except UserModel.DoesNotExist:
|
||||||
raise CommandError(f"No user with email {email} exists.")
|
raise CommandError(f"No user with email {email} exists.")
|
||||||
|
|
||||||
if zipfile.is_zipfile(file):
|
if zipfile.is_zipfile(filename):
|
||||||
with zipfile.ZipFile(file, "r") as zf:
|
with zipfile.ZipFile(filename, "r") as zf:
|
||||||
znames = zf.namelist()
|
znames = zf.namelist()
|
||||||
has_pages = 'pages.json' in znames
|
has_pages = 'pages.json' in znames
|
||||||
has_images = 'images.json' in znames
|
has_images = 'images.json' in znames
|
||||||
@@ -60,9 +59,9 @@ class Command(BaseCommand):
|
|||||||
raise CommandError("Not a valid zipfile!")
|
raise CommandError("Not a valid zipfile!")
|
||||||
|
|
||||||
if has_pages:
|
if has_pages:
|
||||||
import_builtin_pages_from_zip(zip, user)
|
import_builtin_pages_from_zip(filename, user)
|
||||||
if has_images:
|
if has_images:
|
||||||
import_builtin_images_from_zip(zip, user)
|
import_builtin_images_from_zip(filename, user)
|
||||||
else:
|
else:
|
||||||
with open(file, "rt", encoding="utf-8") as json_file:
|
with open(file, "rt", encoding="utf-8") as json_file:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user