2025.09.17-19:07:57

This commit is contained in:
2025-09-17 19:07:58 +02:00
parent ff37c9cd8b
commit 38a85cb9d5
47 changed files with 1530 additions and 38 deletions

View File

@@ -1,6 +1,7 @@
# Generated by Django 5.2.4 on 2025-09-14 13:31
# Generated by Django 5.2.4 on 2025-09-15 00:26
import django.db.models.deletion
import tinywiki.models
from django.conf import settings
from django.db import migrations, models
@@ -22,8 +23,8 @@ class Migration(migrations.Migration):
('alt', models.CharField(max_length=511, verbose_name='alternative text')),
('description', models.CharField(blank=True, max_length=1023, null=True, verbose_name='description')),
('image', models.ImageField(upload_to='tinywiki/img', verbose_name='image file')),
('uploaded_at', models.DateTimeField(auto_now_add=True, verbose_name='upladed at')),
('uploaded_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tinywiki_image_uploads', to=settings.AUTH_USER_MODEL, verbose_name='uploaded by')),
('uploaded_at', models.DateTimeField(auto_now_add=True, verbose_name='uploaded at')),
('uploaded_by', models.ForeignKey(default=tinywiki.models.get_tinywiki_default_user, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='tinywiki_image_uploads', to=settings.AUTH_USER_MODEL, verbose_name='uploaded by')),
],
),
migrations.CreateModel(
@@ -32,13 +33,14 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', models.SlugField(max_length=255, unique=True, verbose_name='slug')),
('title', models.CharField(max_length=255, verbose_name='title')),
('status_data', models.CharField(default='', max_length=15, verbose_name='status')),
('content_type_data', models.CharField(choices=[('markdown', 'Markdown'), ('bbcode', 'BBCode')], default='bbcode', verbose_name='content type')),
('content', models.TextField(verbose_name='Page content')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
('last_edited_at', models.DateTimeField(auto_now=True, verbose_name='last edited at')),
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tinywiki_athors', to=settings.AUTH_USER_MODEL, verbose_name='author')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tinywiki_created', to=settings.AUTH_USER_MODEL, verbose_name='created by')),
('last_edited_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tinywiki_last_edited', to=settings.AUTH_USER_MODEL, verbose_name='last edited by')),
('author', models.ForeignKey(default=tinywiki.models.get_tinywiki_default_user, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='tinywiki_athors', to=settings.AUTH_USER_MODEL, verbose_name='author')),
('created_by', models.ForeignKey(default=tinywiki.models.get_tinywiki_default_user, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='tinywiki_created', to=settings.AUTH_USER_MODEL, verbose_name='created by')),
('last_edited_by', models.ForeignKey(default=tinywiki.models.get_tinywiki_default_user, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='tinywiki_last_edited', to=settings.AUTH_USER_MODEL, verbose_name='last edited by')),
],
),
]

View File

@@ -9,18 +9,90 @@ class Migration(migrations.Migration):
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)
user = get_user_model().objects.create_user(**settings.TINYWIKI_USER_CONFIG)
def init_tinywiki_groups_and_permissions(apps,schema_editor):
from ..models import Page
from django.contrib.auth.models import Group,Permission
from django.contrib.contenttypes.models import ContentType
PERMISSIONS = [
'tinywiki-read-all',
'tinywiki-delete',
'tinywiki-create',
'tinywiki-create-system',
'tinywiki-edit',
'tinywiki-edit-system',
'tinywiki-edit-all',
'tinywiki-delete-all',
'tinywiki-delete-system',
]
GROUPS = [
('tinywiki-moderator',('tinywiki-read-all',
'tinywiki-delete-all',
'tinywiki-edit-all',
'tinywiki-create')),
('tinywiki-author',('tinywiki-create',
'tinywiki-edit',
'tinywiki-delete')),
('tinywiki-reader',('tinywiki-read-all',)),
('tinywiki-admin',('tinywiki-read-all',
'tinywiki-create',
'tinywiki-create-system',
'tinywiki-delete-all',
'tinywiki-delete-system',
'tinywiki-edit-all',
'tinywiki-edit-system'))
]
perm_mapping = {}
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])
def init_default_pages(apps,schema_editor)->None:
from ..models import Page,Image
#TODO
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_user_pages(apps,schema_edit)->None:
from ..models import Page,Image
#TODO
operations = [
migrations.RunPython(init_tinywiki_groups_and_permissions),
migrations.RunPython(init_tinywiki_user),
migrations.RunPython(init_default_pages)
migrations.RunPython(init_default_pages),
]

View File

@@ -0,0 +1,23 @@
[h2]The MIT License (MIT)[/h2]
[h3]Copyright [copy] 2011-2025 The Bootstrap Authors[/h3]
[p]Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
[ul][li]
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.[/li][/ul]
[/p]
[p][b]THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.[/b][/p]

View File

@@ -0,0 +1,10 @@
[h2]Copyright [copy] 2025 Christian Moser[/h2]
[p]Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:[/p]
[ol]
[li]Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.[/li]
[li]Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.[/li]
[/ol]
[p][b]THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[/b][/p]

View File

@@ -0,0 +1,14 @@
{
"tw-license": {
"title": "TinyWiki License",
"content_type":"bbcode",
"status":"published",
"file":"license.bbcode"
},
"tw-bootstrap-license": {
"title": "Bootstrap License",
"content_type": "bbcode",
"status":"published",
"file":"bs-license.bbcode"
}
}