-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ckeditor iframe migrations for plans and offlineevents
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Fixed | ||
|
||
- add migrations for offlineevents and plans to make existing iframes appear in | ||
the new ckeditor5 |
35 changes: 35 additions & 0 deletions
35
meinberlin/apps/offlineevents/migrations/0011_ckeditor_iframes.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,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 = ( | ||
'<figure class="media"><div data-oembed-url="{url}"><div><iframe src="' | ||
'{url}"></iframe></div></div></figure>' | ||
) | ||
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, | ||
), | ||
] |
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,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 = ( | ||
'<figure class="media"><div data-oembed-url="{url}"><div><iframe src="' | ||
'{url}"></iframe></div></div></figure>' | ||
) | ||
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, | ||
), | ||
] |