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
style.css.map style.css.map
style.min.css style.min.css
# Media directory
media

View file

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

View file

@ -42,6 +42,8 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"bulma", "bulma",
"filebrowser",
"tinymce",
"chat.apps.LogsConfig", "chat.apps.LogsConfig",
"khaganat.apps.KhaganatConfig", "khaganat.apps.KhaganatConfig",
"navbar.apps.NavbarConfig", "navbar.apps.NavbarConfig",
@ -166,6 +168,10 @@ STATIC_URL = config("KHAGANAT_STATIC_URL", default="/static/")
STATIC_ROOT = config("KHAGANAT_STATIC_ROOT", default="") or None STATIC_ROOT = config("KHAGANAT_STATIC_ROOT", default="") or None
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static_extra")] STATICFILES_DIRS = [os.path.join(BASE_DIR, "static_extra")]
STATICFILES_DIRS += config("KHAGANAT_STATIC_DIRS", default="", cast=Csv()) or [] 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 # Logs configuration

View file

@ -14,16 +14,23 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.conf import settings
from django.conf.urls.i18n import i18n_patterns from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from pages.views import index from pages.views import index
from filebrowser.sites import site
urlpatterns = [path("", index)] urlpatterns = [path("", index)]
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(
path("", index), path("", index),
# Dependencies
path("tinymce/", include("tinymce.urls")),
path("admin/filebrowser/", site.urls),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
# Khaganat
path("account/", include("neluser.urls")), path("account/", include("neluser.urls")),
path("chat/", include("chat.urls")), path("chat/", include("chat.urls")),
path("nsfw/", include("nsfw.urls")), path("nsfw/", include("nsfw.urls")),
@ -31,3 +38,6 @@ urlpatterns += i18n_patterns(
path("paste/", include("npb.urls", namespace="npb")), path("paste/", include("npb.urls", namespace="npb")),
path("password_share/", include("pwdb.urls")), 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.conf import settings
from django.db import models from django.db import models
import markdown from tinymce import HTMLField
class Page(models.Model): class Page(models.Model):
@ -18,21 +18,7 @@ class PageContent(models.Model):
created_on = models.DateTimeField(auto_now_add=True) created_on = models.DateTimeField(auto_now_add=True)
edited_on = models.DateTimeField(auto_now=True) edited_on = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=200) title = models.CharField(max_length=200)
content = models.TextField() content = HTMLField()
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",
)
def __str__(self): def __str__(self):
return self.title return self.title

View file

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