On migre à CKEditor5

This commit is contained in:
Jean-Marie Favreau 2024-08-29 22:00:09 +02:00
parent bc19358ed3
commit a26d81a74a
5 changed files with 17 additions and 22 deletions

View File

@ -5,7 +5,7 @@ from django.utils.safestring import mark_safe
from django.template.defaultfilters import slugify
from django.urls import reverse
from colorfield.fields import ColorField
from ckeditor.fields import RichTextField
from django_ckeditor_5.fields import CKEditor5Field
from urllib.parse import urlparse
import urllib.request
import os
@ -46,8 +46,9 @@ class StaticContent(models.Model):
max_length=512,
unique=True,
)
text = RichTextField(
verbose_name=_("Content"), help_text=_("Text as shown to the visitors")
text = CKEditor5Field(
verbose_name=_("Content"), help_text=_("Text as shown to the visitors"),
blank=True
)
url_path = models.CharField(
verbose_name=_("URL path"),
@ -450,7 +451,7 @@ class Event(models.Model):
first = self.start_day
last = self.get_consolidated_end_day()
calendar = CalendarList(first, last, exact=True)
return [(len(d.events), d.date) for dstr, d in calendar.calendar_days.items()]
return [(len(d.events), d.date) for dstr, d in calendar.get_calendar_days().items()]
def is_single_day(self, intuitive=True):
return self.start_day == self.get_consolidated_end_day(intuitive)
@ -1201,7 +1202,7 @@ class ContactMessage(models.Model):
blank=True,
null=True,
)
message = RichTextField(verbose_name=_("Message"), help_text=_("Your message"))
message = CKEditor5Field(verbose_name=_("Message"), help_text=_("Your message"), blank=True)
date = models.DateTimeField(auto_now_add=True)
@ -1212,7 +1213,7 @@ class ContactMessage(models.Model):
),
default=False,
)
comments = RichTextField(
comments = CKEditor5Field(
verbose_name=_("Comments"),
help_text=_("Comments on the message from the moderation team"),
default="",

View File

@ -47,7 +47,7 @@ INSTALLED_APPS = [
"django_better_admin_arrayfield",
"django_filters",
"compressor",
"ckeditor",
"django_ckeditor_5",
"recurrence",
"location_field.apps.DefaultConfig",
"django.contrib.postgres",
@ -74,13 +74,12 @@ MIDDLEWARE = [
# "django.middleware.cache.FetchFromCacheMiddleware",
]
CKEDITOR_CONFIGS = {
"default": {
"toolbar": "full",
"removePlugins": "stylesheetparser",
"allowedContent": True,
},
}
CKEDITOR_5_CONFIGS = {
'default': {
'toolbar': ['heading', '|', 'bold', 'italic', 'link', '|',
'bulletedList', 'numberedList', 'blockQuote',],
'language': 'fr',
},}
ROOT_URLCONF = "agenda_culturel.urls"

View File

@ -2,14 +2,6 @@
{% block title %}{% block og_title %}Modifier {{ object.name }}{% endblock %}{% endblock %}
{% block entete_header %}
{% load static %}
<script>window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';</script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
<script src="/static/admin/js/vendor/jquery/jquery.js"></script>
<script src="/static/admin/js/jquery.init.js"></script>
{% endblock %}
{% block content %}
@ -19,5 +11,6 @@
{{ form.as_p }}
<input type="submit" value="Enregistrer">
</form>
{{ form.media }}
{% endblock %}

View File

@ -173,6 +173,7 @@ urlpatterns = [
name="export_ical"),
re_path(r'^robots\.txt', include('robots.urls')),
path("__debug__/", include("debug_toolbar.urls")),
path("ckeditor5/", include('django_ckeditor_5.urls')),
]
if settings.DEBUG:

View File

@ -32,6 +32,7 @@ django-filter==23.3
django-compressor==4.4
django-libsass==0.9
django-ckeditor==6.7.1
django-ckeditor-5==0.2.13
django-recurrence==1.11.1
icalendar==5.0.11
lxml==5.1.0