Skip to content

Commit

Permalink
Update ckeditor5 django fields
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Feb 28, 2024
1 parent c5b600b commit 5fdc46f
Show file tree
Hide file tree
Showing 25 changed files with 581 additions and 142 deletions.
274 changes: 197 additions & 77 deletions adhocracy-plus/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"rules.apps.AutodiscoverRulesConfig",
"easy_thumbnails",
"ckeditor",
"ckeditor_uploader",
"parler",
# Wagtail cms components
"wagtail.contrib.forms",
Expand Down Expand Up @@ -305,120 +304,110 @@
],
}

# CKEditor

CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_RESTRICT_BY_USER = "username"
CKEDITOR_ALLOW_NONIMAGE_FILES = True

CKEDITOR_CONFIGS = {
BLEACH_LIST = {
"default": {
"width": "100%",
"toolbar": "Custom",
"toolbar_Custom": [
["Bold", "Italic", "Underline"],
["NumberedList", "BulletedList"],
["Link", "Unlink"],
"tags": [
"p",
"strong",
"em",
"u",
"ol",
"li",
"ul",
"a",
"img",
"iframe",
"div",
],
"attributes": {
"a": ["href", "rel", "target"],
"img": ["src", "alt", "style"],
"div": ["class"],
"iframe": ["src", "alt", "style"],
},
},
"image-editor": {
"width": "100%",
"toolbar": "Custom",
"toolbar_Custom": [
["Bold", "Italic", "Underline"],
["Image"],
["NumberedList", "BulletedList"],
["Link", "Unlink"],
],
"removeDialogTabs": "image:Link",
},
"collapsible-image-editor": {
"width": "100%",
"title": _("Rich text editor"),
"toolbar": "Custom",
"toolbar_Custom": [
["Bold", "Italic", "Underline"],
["Image"],
["NumberedList", "BulletedList"],
["Link", "Unlink"],
["CollapsibleItem"],
["Embed", "EmbedBase"],
"tags": [
"a",
"em",
"figcaption",
"figure",
"img",
"li",
"ol",
"p",
"span",
"strong",
"u",
"ul",
],
"removePlugins": "stylesheetparser",
"extraAllowedContent": "iframe[*]; div[*]",
"removeDialogTabs": "image:Link",
},
"video-editor": {
"width": "100%",
"title": _("Rich text editor"),
"toolbar": "Custom",
"toolbar_Custom": [["Embed", "EmbedBase"]],
"removePlugins": "stylesheetparser",
"extraAllowedContent": "iframe[*]; div[*]",
},
}

BLEACH_LIST = {
"default": {
"tags": ["p", "strong", "em", "u", "ol", "li", "ul", "a"],
"attributes": {
"a": ["href", "rel", "target"],
"figure": ["class", "style"],
"figcaption": ["class"],
"img": ["class", "src", "alt", "style", "height", "width"],
"span": ["class", "style"],
},
},
"image-editor": {
"tags": ["p", "strong", "em", "u", "ol", "li", "ul", "a", "img"],
"attributes": {"a": ["href", "rel", "target"], "img": ["src", "alt", "style"]},
"styles": [
"aspect-ratio",
"float",
"margin",
"padding",
"width",
"height",
"margin",
"margin-bottom",
"margin-top",
"margin-left",
"margin-right",
"margin-top",
"padding",
"width",
],
},
"collapsible-image-editor": {
"tags": [
"a",
"div",
"em",
"figcaption",
"figure",
"iframe",
"img",
"li",
"ol",
"p",
"span",
"strong",
"em",
"u",
"ol",
"li",
"ul",
"a",
"img",
"div",
"iframe",
],
"attributes": {
"a": ["href", "rel", "target"],
"img": ["src", "alt", "style"],
"div": ["class"],
"iframe": ["src", "alt", "style"],
"div": ["class", "data-oembed-url"],
"figure": ["class", "style"],
"figcaption": ["class"],
"iframe": ["src", "alt"],
"img": ["class", "src", "alt", "style", "height", "width"],
"span": ["class", "style"],
},
"styles": [
"aspect-ratio",
"float",
"margin",
"padding",
"width",
"height",
"margin",
"margin-bottom",
"margin-top",
"margin-left",
"margin-right",
"margin-top",
"padding",
"width",
],
},
"video-editor": {
"tags": ["a", "img", "div", "iframe"],
"tags": ["a", "img", "div", "iframe", "figure"],
"attributes": {
"a": ["href", "rel", "target"],
"img": ["src", "alt", "style"],
"div": ["class"],
"iframe": ["src", "alt", "style"],
"div": ["class", "data-oembed-url"],
"iframe": ["src", "alt"],
"figure": ["class", "div", "iframe"],
},
},
}
Expand Down Expand Up @@ -560,3 +549,134 @@
CELERY_RESULT_BACKEND = "redis://localhost:6379"
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True
CELERY_RESULT_EXTENDED = True

# CKEditor config
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_5_FILE_STORAGE = "adhocracy4.ckeditor.storage.CustomStorage"
CKEDITOR_5_PATH_FROM_USERNAME = True
CKEDITOR_5_ALLOW_ALL_FILE_TYPES = True
CKEDITOR_5_UPLOAD_FILE_TYPES = ["jpg", "jpeg", "png", "gif", "pdf", "docx"]
CKEDITOR_5_CONFIGS = {
"default": {
"language": "de",
"toolbar": [
"bold",
"italic",
"underline",
"|",
"link",
"bulletedList",
"numberedList",
],
"list": {
"properties": {
"styles": "true",
"startIndex": "true",
"reversed": "true",
}
},
"link": {"defaultProtocol": "https://"},
},
"image-editor": {
"language": "de",
"toolbar": {
"items": [
"bold",
"italic",
"underline",
"bulletedList",
"numberedList",
"link",
"imageUpload",
"fileUpload",
],
"shouldNotGroupWhenFull": "true",
},
"image": {
"toolbar": [
"imageUpload",
"imageTextAlternative",
"toggleImageCaption",
"imageStyle:inline",
"imageStyle:wrapText",
"imageStyle:breakText",
"imageStyle:alignLeft",
"imageStyle:alignRight",
],
"insert": {"type": "auto"},
},
"list": {
"properties": {
"styles": "true",
"startIndex": "true",
"reversed": "true",
}
},
"link": {"defaultProtocol": "https://"},
},
"collapsible-image-editor": {
"language": "de",
"toolbar": [
"bold",
"italic",
"underline",
"bulletedList",
"numberedList",
"link",
"imageUpload",
"fileUpload",
"mediaEmbed",
"accordionButton",
"fontSize",
],
"image": {
"toolbar": [
"imageUpload",
"imageTextAlternative",
"toggleImageCaption",
"imageStyle:inline",
"imageStyle:wrapText",
"imageStyle:breakText",
"imageStyle:alignLeft",
"imageStyle:alignRight",
],
"insert": {"type": "auto"},
},
"list": {
"properties": {
"styles": "true",
"startIndex": "true",
"reversed": "true",
}
},
"link": {"defaultProtocol": "https://"},
"mediaEmbed": {
"removeProviders": [
"dailymotion",
"spotify",
"facebook",
"flickr",
"googleMaps",
"instagram",
"twitter",
],
"previewsInData": True,
},
},
"video-editor": {
"language": "de",
"toolbar": ["mediaEmbed"],
"mediaEmbed": {
"removeProviders": [
"dailymotion",
"spotify",
"facebook",
"flickr",
"googleMaps",
"instagram",
"twitter",
],
"previewsInData": True,
},
},
}
12 changes: 3 additions & 9 deletions adhocracy-plus/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""adhocracy+ URL Configuration."""

from ckeditor_uploader import views as ck_views
from django.conf import settings
from django.conf.urls import i18n
from django.contrib import admin
Expand Down Expand Up @@ -107,14 +106,6 @@
re_path(r"^api/", include(router.urls)),
re_path(r"^api/login", obtain_auth_token, name="api-login"),
re_path(r"^api/account/", AccountViewSet.as_view(), name="api-account"),
re_path(
r"^upload/", user_is_project_admin(ck_views.upload), name="ckeditor_upload"
),
re_path(
r"^browse/",
never_cache(user_is_project_admin(ck_views.browse)),
name="ckeditor_browse",
),
re_path(r"^components/$", contrib_views.ComponentLibraryView.as_view()),
re_path(r"^jsi18n/$", JavaScriptCatalog.as_view(), name="javascript-catalog"),
re_path(
Expand Down Expand Up @@ -176,6 +167,9 @@
]
),
),
path(
"ckeditor5/", include("django_ckeditor_5.urls"), name="ck_editor_5_upload_file"
),
path("sitemap.xml", static_sitemap_index, name="static-sitemap-index"),
path("sitemap-wagtail.xml", wagtail_sitemap, name="wagtail-sitemap"),
path(
Expand Down
4 changes: 2 additions & 2 deletions apps/activities/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ckeditor_uploader.widgets import CKEditorUploadingWidget
from django import forms
from django.contrib import admin
from django_ckeditor_5.widgets import CKEditor5Widget

from . import models

Expand All @@ -9,7 +9,7 @@ class ActivityAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["description"].widget = CKEditorUploadingWidget(
self.fields["description"].widget = CKEditor5Widget(
config_name="collapsible-image-editor",
)

Expand Down
6 changes: 4 additions & 2 deletions apps/contrib/templates/a4_candy_contrib/item_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ <h1 class="item-detail__title">{{ object.name }}</h1>
<div class="item-detail__content">
<div class="item-detail__basic-content">
<img class="item-detail__image" src="{% thumbnail object.image 'item_image' %}" alt="">
{{ object.description | richtext }}
<div class="ck-content">
{{ object.description | richtext }}
</div>
</div>

{% block additional_content %}{% endblock %}
Expand Down Expand Up @@ -144,7 +146,7 @@ <h2 class="moderator-feedback__title">{% translate 'Official Feedback' %}</h2>
</strong>
{% html_date object.moderator_feedback_text.created %}
</div>
<div class="moderator-feedback__body">
<div class="moderator-feedback__body ck-content">
{{ object.moderator_feedback_text.feedback_text | safe }}
</div>
</div>
Expand Down
Loading

0 comments on commit 5fdc46f

Please sign in to comment.