mirror of
https://git.cmoser.eu/tinytools/django-tinywiki.git
synced 2026-02-04 06:06:33 +01:00
added twexport command
This commit is contained in:
@@ -262,7 +262,7 @@ def import_builtin_images_from_zip(zip: str | Path, user=None):
|
||||
spec['slug'] = slug
|
||||
spec['user'] = user if user else get_tinywiki_default_user()
|
||||
|
||||
img = Imagwith zie(**spec)
|
||||
img = Image(**spec)
|
||||
with zf.open(image_filename) as ifile:
|
||||
img_file = ImageFile(ifile, image_basename)
|
||||
img.image.save(image_basename, img_file)
|
||||
@@ -271,9 +271,10 @@ def import_builtin_images_from_zip(zip: str | Path, user=None):
|
||||
BuiltinImages.objects.create(app=app, prefix=prefix, version=version)
|
||||
return True
|
||||
|
||||
|
||||
def export_wiki_content(app: str,
|
||||
filename,
|
||||
prefix: str|None = None,
|
||||
prefix: str | None = None,
|
||||
page_version: int = 0,
|
||||
image_version: int = 0) -> bool:
|
||||
prefix = prefix
|
||||
@@ -281,7 +282,7 @@ def export_wiki_content(app: str,
|
||||
bp = BuiltinPages.objects.get(app=app)
|
||||
if page_version < bp.version:
|
||||
page_version = bp.version + 1
|
||||
if prefix is None:
|
||||
if not prefix:
|
||||
prefix = bp.prefix
|
||||
except BuiltinPages.DoesNotExist:
|
||||
bp = None
|
||||
@@ -290,16 +291,16 @@ def export_wiki_content(app: str,
|
||||
bi = BuiltinImages.objects.get(app=app)
|
||||
if image_version < bi.version:
|
||||
image_version = bi.version + 1
|
||||
if prefix is None:
|
||||
if not prefix:
|
||||
prefix = bp.prefix
|
||||
except BuiltinImages.DoesNotExist:
|
||||
bi = None
|
||||
|
||||
if not prefix:
|
||||
raise RuntimeError("No slug prefix! Can not export!", file=sys.stderr)
|
||||
raise RuntimeError("No slug prefix! Can not export!")
|
||||
|
||||
pages = Page.objects.filter(slug__startswith=prefix)
|
||||
images = Image.objects.filter(slug__statrswith=prefix)
|
||||
images = Image.objects.filter(slug__startswith=prefix)
|
||||
|
||||
if not pages and not images:
|
||||
return False
|
||||
@@ -353,7 +354,7 @@ def export_wiki_content(app: str,
|
||||
'description': i.description,
|
||||
}
|
||||
zf.write(i.image.path, arcname)
|
||||
zf.writestr(images.json, json.dumps(images_data, ensure_ascii=False, indent=4))
|
||||
zf.writestr('images.json', json.dumps(images_data, ensure_ascii=False, indent=4))
|
||||
if bi:
|
||||
bi.version = image_version
|
||||
bi.save()
|
||||
|
||||
Reference in New Issue
Block a user