From 85eb1ff03e41511c8d1d15f5c7cb515338543071 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Fri, 28 Feb 2020 13:53:57 +0100 Subject: [PATCH] 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. --- .gitignore | 3 +++ Pipfile | 3 +++ khaganat/settings.py | 6 ++++++ khaganat/urls.py | 10 ++++++++++ pages/migrations/0003_auto_20200228_1214.py | 17 +++++++++++++++++ pages/models.py | 18 ++---------------- pages/templates/pages/page.html | 2 +- 7 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 pages/migrations/0003_auto_20200228_1214.py diff --git a/.gitignore b/.gitignore index 0262ea4..01ba47d 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ Pipfile.lock style.css style.css.map style.min.css + +# Media directory +media diff --git a/Pipfile b/Pipfile index 25edebb..a4ea306 100644 --- a/Pipfile +++ b/Pipfile @@ -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" diff --git a/khaganat/settings.py b/khaganat/settings.py index b344576..a90d953 100644 --- a/khaganat/settings.py +++ b/khaganat/settings.py @@ -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 diff --git a/khaganat/urls.py b/khaganat/urls.py index b078dea..50c3cd9 100644 --- a/khaganat/urls.py +++ b/khaganat/urls.py @@ -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) diff --git a/pages/migrations/0003_auto_20200228_1214.py b/pages/migrations/0003_auto_20200228_1214.py new file mode 100644 index 0000000..9d99742 --- /dev/null +++ b/pages/migrations/0003_auto_20200228_1214.py @@ -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(), + ), + ] diff --git a/pages/models.py b/pages/models.py index c14c0ba..d066d56 100644 --- a/pages/models.py +++ b/pages/models.py @@ -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 diff --git a/pages/templates/pages/page.html b/pages/templates/pages/page.html index 587ce2d..53ded10 100644 --- a/pages/templates/pages/page.html +++ b/pages/templates/pages/page.html @@ -4,6 +4,6 @@ {% block content %}
- {{ page.formated_content|safe }} + {{ page.content|safe }}
{% endblock %}