diff --git a/changelog/_1111.md b/changelog/_1111.md new file mode 100644 index 0000000000..f515a80a9e --- /dev/null +++ b/changelog/_1111.md @@ -0,0 +1,4 @@ +### Fixed + +- add migrations for offlineevents and plans to make existing iframes appear in + the new ckeditor5 diff --git a/meinberlin/apps/offlineevents/migrations/0011_ckeditor_iframes.py b/meinberlin/apps/offlineevents/migrations/0011_ckeditor_iframes.py new file mode 100644 index 0000000000..91ba124bc4 --- /dev/null +++ b/meinberlin/apps/offlineevents/migrations/0011_ckeditor_iframes.py @@ -0,0 +1,35 @@ +# 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 = ( + '
' + ) + OfflineEvent = apps.get_model("meinberlin_offlineevents", "OfflineEvent") + for offline_event in OfflineEvent.objects.all(): + soup = BeautifulSoup(offline_event.description, "html.parser") + iframes = soup.findAll("iframe") + for iframe in iframes: + figure = BeautifulSoup( + template.format(url=iframe.attrs["src"]), "html.parser" + ) + iframe.replaceWith(figure) + if iframes: + offline_event.description = soup.prettify(formatter="html") + offline_event.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("meinberlin_offlineevents", "0010_alter_offlineevent_description"), + ] + + operations = [ + migrations.RunPython( + replace_iframe_with_figur, + ), + ] diff --git a/meinberlin/apps/plans/migrations/0064_ckeditor_iframes.py b/meinberlin/apps/plans/migrations/0064_ckeditor_iframes.py new file mode 100644 index 0000000000..8027ba0385 --- /dev/null +++ b/meinberlin/apps/plans/migrations/0064_ckeditor_iframes.py @@ -0,0 +1,35 @@ +# 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 = ( + '
' + ) + Plan = apps.get_model("meinberlin_plans", "Plan") + for plan in Plan.objects.all(): + soup = BeautifulSoup(plan.description, "html.parser") + iframes = soup.findAll("iframe") + for iframe in iframes: + figure = BeautifulSoup( + template.format(url=iframe.attrs["src"]), "html.parser" + ) + iframe.replaceWith(figure) + if iframes: + plan.description = soup.prettify(formatter="html") + plan.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("meinberlin_plans", "0063_alter_plan_description"), + ] + + operations = [ + migrations.RunPython( + replace_iframe_with_figur, + ), + ]