mirror of
https://git.cmoser.eu/tinytools/django-tinywiki.git
synced 2026-02-04 06:06:33 +01:00
2025.12.23 17:30:33 (cachyos.cmoser.eu)
This commit is contained in:
@@ -7,13 +7,15 @@ class Migration(migrations.Migration):
|
||||
('tinywiki', '0001_initial'),
|
||||
]
|
||||
|
||||
def init_tinywiki_user(apps,schema_editor):
|
||||
@staticmethod
|
||||
def init_tinywiki_user(apps, schema_editor):
|
||||
from django.contrib.auth import get_user_model
|
||||
user = get_user_model().objects.create_user(**settings.TINYWIKI_USER_CONFIG)
|
||||
|
||||
def init_tinywiki_groups_and_permissions(apps,schema_editor):
|
||||
get_user_model().objects.create_user(**settings.TINYWIKI_USER_CONFIG)
|
||||
|
||||
@staticmethod
|
||||
def init_tinywiki_groups_and_permissions(apps, schema_editor):
|
||||
from ..models import Page
|
||||
from django.contrib.auth.models import Group,Permission
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
PERMISSIONS = [
|
||||
@@ -27,7 +29,7 @@ class Migration(migrations.Migration):
|
||||
'tinywiki-delete-all',
|
||||
'tinywiki-delete-system',
|
||||
]
|
||||
|
||||
|
||||
GROUPS = [
|
||||
('tinywiki-moderator',('tinywiki-read-all',
|
||||
'tinywiki-delete-all',
|
||||
@@ -45,79 +47,79 @@ class Migration(migrations.Migration):
|
||||
'tinywiki-edit-all',
|
||||
'tinywiki-edit-system'))
|
||||
]
|
||||
|
||||
|
||||
perm_mapping = {}
|
||||
content_type = ContentType.objects.get_for_model(Page)
|
||||
content_type = ContentType.objects.get_for_model(Page)
|
||||
for perm in PERMISSIONS:
|
||||
permission = Permission.objects.create(codename=perm,content_type=content_type)
|
||||
perm_mapping[perm] = permission
|
||||
|
||||
|
||||
|
||||
for grp,perms in GROUPS:
|
||||
group = Group.objects.create(name=grp)
|
||||
for perm in perms:
|
||||
group.permissions.add(perm_mapping[perm])
|
||||
|
||||
|
||||
group.permissions.add(perm_mapping[perm])
|
||||
|
||||
|
||||
def init_builtin_pages(apps,schema_editor)->None:
|
||||
from ..models import Page,Image
|
||||
from ..enums import WikiContentType,WikiPageStatus
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
|
||||
page_path = Path(__file__).resolve().parent / "pages"
|
||||
json_file = page_path / "pages.json"
|
||||
if json_file.is_file():
|
||||
with open(json_file,"rt",encoding="utf-8") as ifile:
|
||||
data=json.loads(ifile.read())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for slug,spec in data.items():
|
||||
filename = page_path / spec['file']
|
||||
with open(filename,"rt",encoding="utf-8") as ifile:
|
||||
content = ifile.read()
|
||||
|
||||
|
||||
Page.objects.create(slug=slug,
|
||||
title=spec['title'],
|
||||
status_data=WikiPageStatus.from_string(spec['status']).value,
|
||||
content_type_data=WikiContentType.from_string(spec['content_type']).value,
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
@@ -128,4 +130,3 @@ class Migration(migrations.Migration):
|
||||
migrations.RunPython(init_builtin_images),
|
||||
migrations.RunPython(init_builtin_pages),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-23 15:57
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tinywiki', '0002_initial_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SidebarSection',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255, verbose_name='title')),
|
||||
('priority', models.PositiveIntegerField(verbose_name='priority')),
|
||||
('is_visible', models.BooleanField(default=True, verbose_name='is visible')),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='page',
|
||||
name='status_data',
|
||||
field=models.CharField(choices=[('in_progress', 'in progress'), ('draft', 'draft'), ('published', 'published')], default='in_progress', max_length=15, verbose_name='status'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SidebarEntry',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255, verbose_name='Title')),
|
||||
('is_visible', models.BooleanField(default=True, verbose_name='is visible')),
|
||||
('priority', models.PositiveIntegerField(verbose_name='Priority')),
|
||||
('wiki_slug', models.CharField(blank=True, max_length=255, null=True, verbose_name='Wiki slug')),
|
||||
('url', models.CharField(blank=True, max_length=512, null=True, verbose_name='Link URL')),
|
||||
('widget', models.TextField(blank=True, null=True, verbose_name='Widget')),
|
||||
('section', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='tinywiki.sidebarsection', verbose_name='Section')),
|
||||
],
|
||||
),
|
||||
]
|
||||
92
tinywiki/migrations/0004_sidebar.py
Normal file
92
tinywiki/migrations/0004_sidebar.py
Normal file
@@ -0,0 +1,92 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-23 15:59
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@staticmethod
|
||||
def create_tinywiki_sections(apps, schema_editor):
|
||||
from tinywiki.models import SidebarSection, SidebarEntry
|
||||
|
||||
data = [
|
||||
{
|
||||
"title": "TinyWiki Pages",
|
||||
"is_visible": True,
|
||||
"priority": 1000,
|
||||
"items": [
|
||||
{
|
||||
"title": "BBCode Guide",
|
||||
"is_visible": True,
|
||||
"priority": 100,
|
||||
"wiki_slug": "tw-bbcode",
|
||||
},
|
||||
{
|
||||
"title": "Markdown Guide",
|
||||
"is_visible": True,
|
||||
"priority": 90,
|
||||
"wiki_slug": "tw-markdown"
|
||||
},
|
||||
{
|
||||
"title": "TinyWiki License",
|
||||
"is_visible": True,
|
||||
"priority": 80,
|
||||
"wiki_slug": "tw-license"
|
||||
},
|
||||
{
|
||||
"title": "Bootstrap License",
|
||||
"is_visible": True,
|
||||
"priority": 70,
|
||||
"wiki_slug": "tw-bootstrap-license"
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "TinyWiki Seiten",
|
||||
"is_visible": False,
|
||||
"priority": 1000,
|
||||
"items": [
|
||||
{
|
||||
"title": "BBCode Anleitung",
|
||||
"is_visible": True,
|
||||
"priority": 100,
|
||||
"wiki_slug": "tw-de-bbcode",
|
||||
},
|
||||
{
|
||||
"title": "Markdown Anleitung",
|
||||
"is_visible": True,
|
||||
"priority": 90,
|
||||
"wiki_slug": "tw-de-markdown"
|
||||
},
|
||||
{
|
||||
"title": "TinyWiki Lizenz (EN)",
|
||||
"is_visible": True,
|
||||
"priority": 80,
|
||||
"wiki_slug": "tw-license"
|
||||
},
|
||||
{
|
||||
"title": "Bootstrap License (EN)",
|
||||
"is_visible": True,
|
||||
"priority": 70,
|
||||
"wiki_slug": "tw-bootstrap-license"
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
for sect_spec in data:
|
||||
if 'items' in sect_spec:
|
||||
items = sect_spec.pop('items')
|
||||
else:
|
||||
items = []
|
||||
|
||||
section = SidebarSection.objects.create(**sect_spec)
|
||||
for item_spec in items:
|
||||
SidebarEntry.objects.create(section=section, **item_spec)
|
||||
|
||||
dependencies = [
|
||||
('tinywiki', '0003_sidebarsection_alter_page_status_data_sidebarentry'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
Reference in New Issue
Block a user