2025.10.06-03:08:05
This commit is contained in:
@@ -59,7 +59,7 @@ class Migration(migrations.Migration):
|
||||
group.permissions.add(perm_mapping[perm])
|
||||
|
||||
|
||||
def init_default_pages(apps,schema_editor)->None:
|
||||
def init_builtin_pages(apps,schema_editor)->None:
|
||||
from ..models import Page,Image
|
||||
from ..enums import WikiContentType,WikiPageStatus
|
||||
from pathlib import Path
|
||||
@@ -85,14 +85,47 @@ class Migration(migrations.Migration):
|
||||
content=content)
|
||||
|
||||
|
||||
def init_builtin_images(apps,schema_edit):
|
||||
from pathlib import Path
|
||||
from ..models import Image
|
||||
from django.core.files.images import ImageFile
|
||||
import json
|
||||
|
||||
def init_user_pages(apps,schema_edit)->None:
|
||||
from ..models import Page,Image
|
||||
image_dir = Path(__file__).resolve().parent / "images"
|
||||
images_json_file = image_dir/ "images.json"
|
||||
|
||||
if not images_json_file.is_file():
|
||||
return
|
||||
|
||||
with open(images_json_file,"rt",encoding="utf-8") as ifile:
|
||||
images_data = json.loads(ifile.read())
|
||||
|
||||
for slug,_spec in images_data.items():
|
||||
spec = dict(_spec)
|
||||
image_basename = spec['image']
|
||||
image_filename = image_dir / spec["image"]
|
||||
spec['slug'] = slug
|
||||
del spec['image']
|
||||
|
||||
img = Image(**spec)
|
||||
with open(image_filename,"rb") as ifile:
|
||||
img_file = ImageFile(ifile,image_basename)
|
||||
img.image.save(image_basename,img_file)
|
||||
img.save()
|
||||
|
||||
|
||||
def init_user_imges(apps,schema_edit)->None:
|
||||
#TODO
|
||||
pass
|
||||
|
||||
def init_user_pages(apps,schema_edit)->None:
|
||||
#TODO
|
||||
pass
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(init_tinywiki_groups_and_permissions),
|
||||
migrations.RunPython(init_tinywiki_user),
|
||||
migrations.RunPython(init_default_pages),
|
||||
migrations.RunPython(init_builtin_images),
|
||||
migrations.RunPython(init_builtin_pages),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user