-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace django-ckedtitor with django-ckeditor-5
- Loading branch information
Showing
18 changed files
with
170 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-419 Bytes
adhocracy4/ckeditor/static/ckeditor_collapsible/icons/collapsibleitem.png
Binary file not shown.
Binary file removed
BIN
-991 Bytes
adhocracy4/ckeditor/static/ckeditor_collapsible/icons/hidpi/collapsibleitem.png
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
from urllib.parse import urljoin | ||
|
||
from django.conf import settings | ||
from django.core.files.storage import FileSystemStorage | ||
|
||
|
||
class CustomStorage(FileSystemStorage): | ||
"""Custom storage to store uploads in a subfolder called uploads""" | ||
|
||
location = os.path.join(settings.MEDIA_ROOT, "uploads") | ||
base_url = urljoin(settings.MEDIA_URL, "uploads/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 3.2.20 on 2023-09-19 09:52 | ||
|
||
from django.db import migrations | ||
import django_ckeditor_5.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0039_add_alt_text_to_field"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="project", | ||
name="information", | ||
field=django_ckeditor_5.fields.CKEditor5Field( | ||
blank=True, | ||
help_text="This description should tell participants what the goal of the project is, how the project’s participation will look like. It will be always visible in the „Info“ tab on your project’s page.", | ||
verbose_name="Description of your project", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="project", | ||
name="result", | ||
field=django_ckeditor_5.fields.CKEditor5Field( | ||
blank=True, | ||
help_text="Here you should explain what the expected outcome of the project will be and how you are planning to use the results. If the project is finished you should add a summary of the results.", | ||
verbose_name="Results of your project", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 3.2.20 on 2023-11-16 11:35 | ||
|
||
from bs4 import BeautifulSoup | ||
from django.db import migrations | ||
|
||
|
||
def replace_iframe_with_figur(apps, schema_editor): | ||
template = ( | ||
'<figure class="media"><div data-oembed-url="{url}"><div><iframe src="' | ||
'{url}"></iframe></div></div></figure>' | ||
) | ||
Project = apps.get_model("a4projects", "Project") | ||
informations = 0 | ||
results = 0 | ||
for project in Project.objects.all(): | ||
soup = BeautifulSoup(project.information, "html.parser") | ||
iframes = soup.findAll("iframe") | ||
changed = False | ||
for iframe in iframes: | ||
figure = BeautifulSoup( | ||
template.format(url=iframe.attrs["src"]), "html.parser" | ||
) | ||
iframe.replaceWith(figure) | ||
informations += 1 | ||
if iframes: | ||
project.information = soup.prettify(formatter="html") | ||
changed = True | ||
soup = BeautifulSoup(project.result, "html.parser") | ||
iframes = soup.findAll("iframe") | ||
for iframe in iframes: | ||
figure = BeautifulSoup( | ||
template.format(url=iframe.attrs["src"]), "html.parser" | ||
) | ||
iframe.replaceWith(figure) | ||
results += 1 | ||
if iframes: | ||
project.result = soup.prettify(formatter="html") | ||
changed = True | ||
if changed: | ||
project.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0040_auto_20230919_0952"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
replace_iframe_with_figur, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### Added | ||
|
||
- custom migration for iframes to make them work with ckeditor5 (WARNING: | ||
backing up your database before running is recommended). | ||
- added dependency beautifulsoup4 | ||
|
||
### Changed | ||
|
||
- replace django-ckeditor with django-ckeditor-5 | ||
|
||
### Removed | ||
|
||
- removed RichTextCollapsibleField | ||
- removed RichtTextCollapsibleMixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/apps/ideas/migrations/0006_alter_idea_description.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 3.2.20 on 2023-09-19 13:10 | ||
|
||
from django.db import migrations | ||
import django_ckeditor_5.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4test_ideas", "0005_idea_is_bool_test"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="idea", | ||
name="description", | ||
field=django_ckeditor_5.fields.CKEditor5Field( | ||
blank=True, verbose_name="Description" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tests/apps/moderatorfeedback/migrations/0005_alter_moderatorfeedback_feedback_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.20 on 2023-09-19 13:10 | ||
|
||
from django.db import migrations | ||
import django_ckeditor_5.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("moderatorfeedback", "0004_verbose_name_created_modified"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="moderatorfeedback", | ||
name="feedback_text", | ||
field=django_ckeditor_5.fields.CKEditor5Field(blank=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from ckeditor.fields import RichTextField | ||
from django_ckeditor_5.fields import CKEditor5Field | ||
|
||
from adhocracy4.models.base import UserGeneratedContentModel | ||
|
||
|
||
class ModeratorFeedback(UserGeneratedContentModel): | ||
feedback_text = RichTextField( | ||
feedback_text = CKEditor5Field( | ||
blank=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf import settings | ||
|
||
from adhocracy4.ckeditor.storage import CustomStorage | ||
|
||
|
||
def test_ckeditor_storage_backend(): | ||
storage = CustomStorage() | ||
assert storage.path("test.txt").endswith(settings.MEDIA_ROOT + "/uploads/test.txt") |
This file was deleted.
Oops, something went wrong.