From 95430a33c4adc98a9178b8762792ba6608c917b8 Mon Sep 17 00:00:00 2001 From: Mara Karagianni Date: Tue, 26 Mar 2024 15:25:44 +0200 Subject: [PATCH] ideas,moderatorfeedback,organisations: replace richtext with ckeditor --- .../0003_alter_proposal_description.py | 18 +++++++ .../migrations/0003_alter_idea_description.py | 18 +++++++ apps/ideas/models.py | 4 +- .../0003_alter_mapidea_description.py | 18 +++++++ apps/moderatorfeedback/forms.py | 8 +++ .../migrations/0006_auto_20240326_1134.py | 27 ++++++++++ apps/moderatorfeedback/models.py | 11 ++--- apps/organisations/forms.py | 21 +++++--- .../migrations/0024_auto_20240326_1134.py | 49 +++++++++++++++++++ apps/organisations/models.py | 9 ++-- 10 files changed, 160 insertions(+), 23 deletions(-) create mode 100644 apps/budgeting/migrations/0003_alter_proposal_description.py create mode 100644 apps/ideas/migrations/0003_alter_idea_description.py create mode 100644 apps/mapideas/migrations/0003_alter_mapidea_description.py create mode 100644 apps/moderatorfeedback/migrations/0006_auto_20240326_1134.py create mode 100644 apps/organisations/migrations/0024_auto_20240326_1134.py diff --git a/apps/budgeting/migrations/0003_alter_proposal_description.py b/apps/budgeting/migrations/0003_alter_proposal_description.py new file mode 100644 index 0000000000..c0ffc0b184 --- /dev/null +++ b/apps/budgeting/migrations/0003_alter_proposal_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2024-03-26 10:34 + +from django.db import migrations +import django_ckeditor_5.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_budgeting", "0002_rename_moderatorfeedback_fields"), + ] + + operations = [ + migrations.AlterField( + model_name="proposal", + name="description", + field=django_ckeditor_5.fields.CKEditor5Field(verbose_name="Description"), + ), + ] diff --git a/apps/ideas/migrations/0003_alter_idea_description.py b/apps/ideas/migrations/0003_alter_idea_description.py new file mode 100644 index 0000000000..d8f4a012ae --- /dev/null +++ b/apps/ideas/migrations/0003_alter_idea_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2024-03-26 10:34 + +from django.db import migrations +import django_ckeditor_5.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_ideas", "0002_rename_moderatorfeedback_fields"), + ] + + operations = [ + migrations.AlterField( + model_name="idea", + name="description", + field=django_ckeditor_5.fields.CKEditor5Field(verbose_name="Description"), + ), + ] diff --git a/apps/ideas/models.py b/apps/ideas/models.py index c9aa25f329..18ea486806 100644 --- a/apps/ideas/models.py +++ b/apps/ideas/models.py @@ -1,10 +1,10 @@ from autoslug import AutoSlugField -from ckeditor.fields import RichTextField from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType from django.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ +from django_ckeditor_5.fields import CKEditor5Field from adhocracy4 import transforms from adhocracy4.categories.fields import CategoryField @@ -31,7 +31,7 @@ class AbstractIdea(module_models.Item, Moderateable): ) slug = AutoSlugField(populate_from="name", unique=True) name = models.CharField(max_length=120, verbose_name=_("Title")) - description = RichTextField(verbose_name=_("Description")) + description = CKEditor5Field(verbose_name=_("Description")) image = ConfiguredImageField( "idea_image", verbose_name=_("Add image"), diff --git a/apps/mapideas/migrations/0003_alter_mapidea_description.py b/apps/mapideas/migrations/0003_alter_mapidea_description.py new file mode 100644 index 0000000000..a246a9b997 --- /dev/null +++ b/apps/mapideas/migrations/0003_alter_mapidea_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2024-03-26 10:34 + +from django.db import migrations +import django_ckeditor_5.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_mapideas", "0002_moderatorfeedback_fields"), + ] + + operations = [ + migrations.AlterField( + model_name="mapidea", + name="description", + field=django_ckeditor_5.fields.CKEditor5Field(verbose_name="Description"), + ), + ] diff --git a/apps/moderatorfeedback/forms.py b/apps/moderatorfeedback/forms.py index d15b7ab29f..6669c53271 100644 --- a/apps/moderatorfeedback/forms.py +++ b/apps/moderatorfeedback/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.utils.translation import gettext_lazy as _ from . import models @@ -7,3 +8,10 @@ class ModeratorFeedbackForm(forms.ModelForm): class Meta: model = models.ModeratorFeedback fields = ["feedback_text"] + help_texts = { + "feedback_text": _( + "The official feedback will appear below the idea, " + "indicating your organisation. The idea provider receives " + "a notification." + ), + } diff --git a/apps/moderatorfeedback/migrations/0006_auto_20240326_1134.py b/apps/moderatorfeedback/migrations/0006_auto_20240326_1134.py new file mode 100644 index 0000000000..46fe38a5b0 --- /dev/null +++ b/apps/moderatorfeedback/migrations/0006_auto_20240326_1134.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.19 on 2024-03-26 10:34 + +from django.db import migrations +import django_ckeditor_5.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_moderatorfeedback", "0005_moderatorcommentfeedback"), + ] + + operations = [ + migrations.AlterField( + model_name="moderatorcommentfeedback", + name="feedback_text", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, verbose_name="Moderator feedback" + ), + ), + migrations.AlterField( + model_name="moderatorfeedback", + name="feedback_text", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, verbose_name="Official feedback" + ), + ), + ] diff --git a/apps/moderatorfeedback/models.py b/apps/moderatorfeedback/models.py index 2ac0bc53e0..bc1115a548 100644 --- a/apps/moderatorfeedback/models.py +++ b/apps/moderatorfeedback/models.py @@ -1,6 +1,6 @@ -from ckeditor.fields import RichTextField from django.db import models from django.utils.translation import gettext_lazy as _ +from django_ckeditor_5.fields import CKEditor5Field from adhocracy4 import transforms from adhocracy4.comments.models import Comment @@ -16,14 +16,9 @@ class ModeratorFeedback(UserGeneratedContentModel): - feedback_text = RichTextField( + feedback_text = CKEditor5Field( blank=True, verbose_name=_("Official feedback"), - help_text=_( - "The official feedback will appear below the idea, " - "indicating your organisation. The idea provider receives " - "a notification." - ), ) def save(self, *args, **kwargs): @@ -56,7 +51,7 @@ class Meta: class ModeratorCommentFeedback(UserGeneratedContentModel): - feedback_text = RichTextField( + feedback_text = CKEditor5Field( blank=True, verbose_name=_("Moderator feedback"), ) diff --git a/apps/organisations/forms.py b/apps/organisations/forms.py index 54c6239d5d..edf8fe3fb3 100644 --- a/apps/organisations/forms.py +++ b/apps/organisations/forms.py @@ -137,14 +137,6 @@ class OrganisationForm(forms.ModelForm): CKEditor5Widget, { "config_name": "collapsible-image-editor", - "help_text": OrganisationTranslation._meta.get_field( - "information" - ).help_text, - "external_plugin_resources": _external_plugin_resources, - "extra_plugins": ["collapsibleItem"], - "widget": CKEditor5Widget( - config_name="collapsible-image-editor", - ), }, ), ] @@ -170,6 +162,7 @@ def __init__(self, *args, **kwargs): for lang_code in self.languages: for name, field_cls, kwargs in self.translated_fields: self.instance.set_current_language(lang_code) + print(field_cls) field = field_cls(**kwargs) # The CKEditor5Widget doesn't have a label field, so we need to set it # after creating the object @@ -179,6 +172,18 @@ def __init__(self, *args, **kwargs): "information" ).verbose_name, ) + field.help_text = ( + OrganisationTranslation._meta.get_field( + "information" + ).help_text, + ) + field.external_plugin_resources = (_external_plugin_resources,) + field.external_plugins = (["collapsibleItem"],) + field.widget = ( + CKEditor5Widget( + config_name="collapsible-image-editor", + ), + ) identifier = self._get_identifier(lang_code, name) field.required = False diff --git a/apps/organisations/migrations/0024_auto_20240326_1134.py b/apps/organisations/migrations/0024_auto_20240326_1134.py new file mode 100644 index 0000000000..fd05dd7e82 --- /dev/null +++ b/apps/organisations/migrations/0024_auto_20240326_1134.py @@ -0,0 +1,49 @@ +# Generated by Django 3.2.19 on 2024-03-26 10:34 + +from django.db import migrations +import django_ckeditor_5.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_organisations", "0023_alter_organisationtranslation_information"), + ] + + operations = [ + migrations.AlterField( + model_name="organisation", + name="data_protection", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, + help_text="Please provide all the legally required information of your data protection. The data protection policy will be shown on a separate page.", + verbose_name="Data protection policy", + ), + ), + migrations.AlterField( + model_name="organisation", + name="imprint", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, + help_text="Please provide all the legally required information of your imprint. The imprint will be shown on a separate page.", + verbose_name="Imprint", + ), + ), + migrations.AlterField( + model_name="organisation", + name="netiquette", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, + help_text="Please provide a netiquette for the participants. The netiquette helps improving the climate of online discussions and supports the moderation.", + verbose_name="Netiquette", + ), + ), + migrations.AlterField( + model_name="organisation", + name="terms_of_use", + field=django_ckeditor_5.fields.CKEditor5Field( + blank=True, + help_text="Please provide all the legally required information of your terms of use. The terms of use will be shown on a separate page.", + verbose_name="Terms of use", + ), + ), + ] diff --git a/apps/organisations/models.py b/apps/organisations/models.py index bc544f9d4a..515f7df994 100644 --- a/apps/organisations/models.py +++ b/apps/organisations/models.py @@ -1,5 +1,4 @@ from autoslug import AutoSlugField -from ckeditor.fields import RichTextField from django.conf import settings from django.contrib.sites.models import Site from django.db import models @@ -120,7 +119,7 @@ class Organisation(TranslatableModel): blank=True, verbose_name="Instagram handle", ) - imprint = RichTextField( + imprint = CKEditor5Field( verbose_name=_("Imprint"), help_text=_( "Please provide all the legally " @@ -129,7 +128,7 @@ class Organisation(TranslatableModel): ), blank=True, ) - terms_of_use = RichTextField( + terms_of_use = CKEditor5Field( verbose_name=_("Terms of use"), help_text=_( "Please provide all the legally " @@ -138,7 +137,7 @@ class Organisation(TranslatableModel): ), blank=True, ) - data_protection = RichTextField( + data_protection = CKEditor5Field( verbose_name=_("Data protection policy"), help_text=_( "Please provide all the legally " @@ -148,7 +147,7 @@ class Organisation(TranslatableModel): ), blank=True, ) - netiquette = RichTextField( + netiquette = CKEditor5Field( verbose_name=_("Netiquette"), help_text=_( "Please provide a netiquette for the participants. "