2025.09.14-18:02:28

This commit is contained in:
2025-09-14 18:02:28 +02:00
parent 565ef0cad1
commit ff37c9cd8b
32 changed files with 733 additions and 22 deletions

91
tinywiki/models.py Normal file
View File

@@ -0,0 +1,91 @@
from tabnanny import verbose
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils.safestring import mark_safe,SafeText
from tinywiki.enums import WIKI_CONTENT_TYPES, WikiContentType
import markdown
import bbcode
class Page(models.Model):
slug = models.SlugField(_("slug"),
max_length=255,
null=False,
blank=False,
unique=True)
title = models.CharField(_("title"),
max_length=255,
null=False,
blank=False)
author = models.ForeignKey(get_user_model(),
on_delete=models.SET_NULL,
verbose_name=_("author"),
null=True,
blank=True,
related_name="tinywiki_athors")
content_type_data = models.CharField(_("content type"),
choices=[(i.value,i.str_lazy) for i in WIKI_CONTENT_TYPES],
default=WikiContentType.BBCODE.value)
content = models.TextField(_("Page content"),
null=False,
blank=False)
created_at = models.DateTimeField(_("created at"),
auto_now_add=True)
created_by = models.ForeignKey(get_user_model(),
on_delete=models.SET_NULL,
verbose_name=_("created by"),
null=True,
blank=True,
related_name="tinywiki_created")
last_edited_at = models.DateTimeField(_("last edited at"),
auto_now=True)
last_edited_by = models.ForeignKey(get_user_model(),
on_delete=models.SET_NULL,
verbose_name=_("last edited by"),
null=True,
blank=True,
related_name="tinywiki_last_edited")
@property
def content_type(self)->WikiContentType:
return WikiContentType.from_string(self.content_type_data)
@property
def html_content(self)->SafeText|str:
if self.content_type == WikiContentType.MARKDOWN:
return mark_safe(markdown.markdown(self.content))
elif self.content_type == WikiContentType.BBCODE:
return mark_safe(bbcode.render_html(self.content))
return self.content
class Image(models.Model):
models.ManyToManyField(Page, verbose_name=_(""))
slug = models.SlugField(_("slug"),
max_length=255)
alt = models.CharField(_("alternative text"),
max_length=511,
null=False,
blank=False)
description = models.CharField(_("description"),
max_length=1023,
null=True,
blank=True)
image = models.ImageField(_("image file"),
upload_to="tinywiki/img")
uploaded_by = models.ForeignKey(get_user_model(),
on_delete=models.SET_NULL,
verbose_name=_("uploaded by"),
null=True,
blank=True,
related_name="tinywiki_image_uploads")
uploaded_at = models.DateTimeField(_("uploaded at"),
auto_now_add=True)