From 954f4ff010f73b4b4471b9b5efe830d7c8442709 Mon Sep 17 00:00:00 2001 From: AlexandreJunod Date: Mon, 11 Mar 2024 15:33:01 +0100 Subject: [PATCH] data migration to add raw-html-embed --- .../0032_data_migration_sectionparagraph.py | 33 +++++++++++++++++++ geocity/settings.py | 1 + 2 files changed, 34 insertions(+) create mode 100644 geocity/apps/reports/migrations/0032_data_migration_sectionparagraph.py diff --git a/geocity/apps/reports/migrations/0032_data_migration_sectionparagraph.py b/geocity/apps/reports/migrations/0032_data_migration_sectionparagraph.py new file mode 100644 index 000000000..354e78fe2 --- /dev/null +++ b/geocity/apps/reports/migrations/0032_data_migration_sectionparagraph.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.1 on 2023-06-15 16:21 + +from django.db import migrations + + +class Migration(migrations.Migration): + def update_sectionparagraph(apps, schema_editor): + + SectionParagraph = apps.get_model("reports", "SectionParagraph") + html_embed_open = '
' + html_embed_close = "
" + + # Update sections containing "div" or "class" or "table" + sections_with_keywords = ( + SectionParagraph.objects.filter(content__contains="div") + | SectionParagraph.objects.filter(content__contains="class") + | SectionParagraph.objects.filter(content__contains="table") + ) + + for section in sections_with_keywords: + section.content = f"{html_embed_open}{section.content}{html_embed_close}" + section.save(update_fields=["content"]) + + dependencies = [ + ( + "reports", + "0031_alter_sectionrecipient_first_recipient_and_more", + ), + ] + + operations = [ + migrations.RunPython(update_sectionparagraph), + ] diff --git a/geocity/settings.py b/geocity/settings.py index 99b34701b..6f95dbe45 100644 --- a/geocity/settings.py +++ b/geocity/settings.py @@ -661,6 +661,7 @@ "items": [ "undo", "redo", + "htmlEmbed", "sourceEditing", "|", "heading",