Skip to content

Commit

Permalink
Merge pull request #1437 from betagouv/1408-django-ckeditor-replacement
Browse files Browse the repository at this point in the history
Mise en place de django-prose pour remplacer django-ckeditor
  • Loading branch information
hfroot authored Jan 8, 2025
2 parents c2067dc + 3235e54 commit 290fb20
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 12 deletions.
1 change: 1 addition & 0 deletions api/serializers/blogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Meta:
"title",
"tagline",
"body",
"content",
"published",
"display_date",
"author",
Expand Down
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"rest_framework",
"webpack_loader",
"django_ckeditor_5",
"prose",
"anymail",
"simple_history",
"django_extensions",
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("ckeditor5/", include("django_ckeditor_5.urls"), name="ck_editor_5_upload_file"),
path("prose/", include("prose.urls")),
path("hijack/", include("hijack.urls")),
]
urlpatterns.append(re_path(r"", include(("web.urls", "web"), namespace="web")))
Expand Down
22 changes: 15 additions & 7 deletions data/admin/blogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ class Meta:
@admin.register(BlogPost)
class BlogPostAdmin(admin.ModelAdmin):
form = BlogPostForm
fields = (
"title",
"tagline",
"display_date",
"published",
"author",
"body",
fieldsets = (
(
"",
{
"fields": (
"title",
"tagline",
"display_date",
"published",
"author",
"content",
)
},
),
("Contenu legacy (ne plus utiliser)", {"fields": ("body",)}),
)
list_display = (
"title",
Expand Down
3 changes: 3 additions & 0 deletions data/factories/blogpost.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import factory

from data.models import BlogPost

from .user import UserFactory


Expand All @@ -10,5 +12,6 @@ class Meta:
title = factory.Faker("catch_phrase")
tagline = factory.Faker("catch_phrase")
body = factory.Faker("paragraph")
content = factory.Faker("paragraph")
published = factory.Faker("boolean")
author = factory.SubFactory(UserFactory)
25 changes: 25 additions & 0 deletions data/migrations/0112_blogpost_content_alter_blogpost_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2025-01-07 15:28

import django_ckeditor_5.fields
import prose.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('data', '0111_alter_declaredingredient_request_status_and_more'),
]

operations = [
migrations.AddField(
model_name='blogpost',
name='content',
field=prose.fields.RichTextField(blank=True, null=True, verbose_name='contenu'),
),
migrations.AlterField(
model_name='blogpost',
name='body',
field=django_ckeditor_5.fields.CKEditor5Field(blank=True, null=True, verbose_name='contenu (legacy)'),
),
]
4 changes: 3 additions & 1 deletion data/models/blogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils import timezone

from django_ckeditor_5.fields import CKEditor5Field
from prose.fields import RichTextField


class BlogPost(models.Model):
Expand All @@ -17,7 +18,8 @@ class Meta:
title = models.TextField(verbose_name="titre")
tagline = models.TextField(null=True, blank=True, verbose_name="description courte")
display_date = models.DateField(default=timezone.now, verbose_name="date affichée")
body = CKEditor5Field(null=True, blank=True, verbose_name="contenu")
body = CKEditor5Field(null=True, blank=True, verbose_name="contenu (legacy)")
content = RichTextField(null=True, blank=True, verbose_name="contenu")
published = models.BooleanField(default=False, verbose_name="publié")
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/BlogPostPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1 class="fr-h4">{{ blogPost.title }}</h1>
<p class="my-0">{{ author }}</p>
<p class="fr-text--xs my-0">{{ date }}</p>
<div id="content" v-html="blogPost.body" class="text-left"></div>
<div id="content" v-html="blogPost.content || blogPost.body" class="text-left"></div>
</div>
</template>

Expand Down
37 changes: 34 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bs4 = "^0.0.2"
#########################
django-hijack = "^3.7.1"
pandas = "^2.2.3"
django-prose = "^2.1.0"
[tool.poetry.group.dev.dependencies]
sqlfluff = "*"

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async-timeout==5.0.1 ; python_version >= "3.11" and python_full_version < "3.11.
autopep8==2.3.1 ; python_version >= "3.11" and python_version < "4"
beautifulsoup4==4.12.3 ; python_version >= "3.11" and python_version < "4"
billiard==4.2.1 ; python_version >= "3.11" and python_version < "4"
bleach==6.2.0 ; python_version >= "3.11" and python_version < "4.0"
boto3==1.35.92 ; python_version >= "3.11" and python_version < "4"
botocore==1.35.92 ; python_version >= "3.11" and python_version < "4"
bs4==0.0.2 ; python_version >= "3.11" and python_version < "4"
Expand Down Expand Up @@ -34,6 +35,7 @@ django-filter==24.3 ; python_version >= "3.11" and python_version < "4"
django-hijack==3.7.1 ; python_version >= "3.11" and python_version < "4"
django-js-asset==2.2.0 ; python_version >= "3.11" and python_version < "4"
django-phonenumber-field[phonenumbers]==8.0.0 ; python_version >= "3.11" and python_version < "4"
django-prose==2.1.0 ; python_version >= "3.11" and python_version < "4.0"
django-silk==5.3.2 ; python_version >= "3.11" and python_version < "4"
django-simple-history==3.7.0 ; python_version >= "3.11" and python_version < "4"
django-storages==1.14.4 ; python_version >= "3.11" and python_version < "4"
Expand Down

0 comments on commit 290fb20

Please sign in to comment.