Skip to content

Commit

Permalink
ideas,moderatorfeedback,organisations: replace richtext with ckeditor
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Mar 26, 2024
1 parent 9cc7bfb commit 95430a3
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 23 deletions.
18 changes: 18 additions & 0 deletions apps/budgeting/migrations/0003_alter_proposal_description.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
18 changes: 18 additions & 0 deletions apps/ideas/migrations/0003_alter_idea_description.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
4 changes: 2 additions & 2 deletions apps/ideas/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"),
Expand Down
18 changes: 18 additions & 0 deletions apps/mapideas/migrations/0003_alter_mapidea_description.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
8 changes: 8 additions & 0 deletions apps/moderatorfeedback/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import forms
from django.utils.translation import gettext_lazy as _

from . import models

Expand All @@ -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."
),
}
27 changes: 27 additions & 0 deletions apps/moderatorfeedback/migrations/0006_auto_20240326_1134.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
11 changes: 3 additions & 8 deletions apps/moderatorfeedback/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -56,7 +51,7 @@ class Meta:


class ModeratorCommentFeedback(UserGeneratedContentModel):
feedback_text = RichTextField(
feedback_text = CKEditor5Field(
blank=True,
verbose_name=_("Moderator feedback"),
)
Expand Down
21 changes: 13 additions & 8 deletions apps/organisations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
},
),
]
Expand All @@ -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
Expand All @@ -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

Expand Down
49 changes: 49 additions & 0 deletions apps/organisations/migrations/0024_auto_20240326_1134.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
9 changes: 4 additions & 5 deletions apps/organisations/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand All @@ -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. "
Expand Down

0 comments on commit 95430a3

Please sign in to comment.