Refactor the page edition

Markdown has been removed, pages are now directly edited in HTML. To
ease that process, TinyMCE has been added. Also, the admin dashboard now
provides a file management tool in order to upload stuff.
This commit is contained in:
Rodolphe Breard 2020-02-28 13:53:57 +01:00
parent fdced02f0c
commit 85eb1ff03e
7 changed files with 42 additions and 17 deletions

3
.gitignore vendored
View file

@ -52,3 +52,6 @@ Pipfile.lock
style.css
style.css.map
style.min.css
# Media directory
media

View file

@ -6,8 +6,11 @@ name = "pypi"
[packages]
django = "~=3.0.3"
django-bulma = "*"
django-filebrowser-no-grappelli = "*"
django-npb = "*"
django-tinymce4-lite = "*"
markdown = "*"
pillow = ">=7"
python-decouple = "*"
cryptography = ">=2.8"

View file

@ -42,6 +42,8 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"bulma",
"filebrowser",
"tinymce",
"chat.apps.LogsConfig",
"khaganat.apps.KhaganatConfig",
"navbar.apps.NavbarConfig",
@ -166,6 +168,10 @@ STATIC_URL = config("KHAGANAT_STATIC_URL", default="/static/")
STATIC_ROOT = config("KHAGANAT_STATIC_ROOT", default="") or None
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static_extra")]
STATICFILES_DIRS += config("KHAGANAT_STATIC_DIRS", default="", cast=Csv()) or []
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
FILEBROWSER_DIRECTORY = "uploads/"
FILEBROWSER_VERSIONS_BASEDIR = "_version/"
# Logs configuration

View file

@ -14,16 +14,23 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.views.generic.base import RedirectView
from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from pages.views import index
from filebrowser.sites import site
urlpatterns = [path("", index)]
urlpatterns += i18n_patterns(
path("", index),
# Dependencies
path("tinymce/", include("tinymce.urls")),
path("admin/filebrowser/", site.urls),
path("admin/", admin.site.urls),
# Khaganat
path("account/", include("neluser.urls")),
path("chat/", include("chat.urls")),
path("nsfw/", include("nsfw.urls")),
@ -31,3 +38,6 @@ urlpatterns += i18n_patterns(
path("paste/", include("npb.urls", namespace="npb")),
path("password_share/", include("pwdb.urls")),
)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View file

@ -0,0 +1,17 @@
# Generated by Django 3.0.3 on 2020-02-28 11:14
from django.db import migrations
import tinymce.models
class Migration(migrations.Migration):
dependencies = [
("pages", "0002_page_is_nsfw"),
]
operations = [
migrations.AlterField(
model_name="pagecontent", name="content", field=tinymce.models.HTMLField(),
),
]

View file

@ -1,6 +1,6 @@
from django.conf import settings
from django.db import models
import markdown
from tinymce import HTMLField
class Page(models.Model):
@ -18,21 +18,7 @@ class PageContent(models.Model):
created_on = models.DateTimeField(auto_now_add=True)
edited_on = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=200)
content = models.TextField()
def formated_content(self):
return markdown.markdown(
self.content,
extensions=[
"markdown.extensions.extra",
"markdown.extensions.admonition",
"markdown.extensions.nl2br",
"markdown.extensions.sane_lists",
"markdown.extensions.smarty",
"markdown.extensions.toc",
],
output_format="html5",
)
content = HTMLField()
def __str__(self):
return self.title

View file

@ -4,6 +4,6 @@
{% block content %}
<div class="content">
{{ page.formated_content|safe }}
{{ page.content|safe }}
</div>
{% endblock %}