diff --git a/district/migrations/0043_auto_20220313_1732.py b/district/migrations/0043_auto_20220313_1732.py deleted file mode 100644 index 29a2250908939afb94c3699f724a976bfd5dda1b..0000000000000000000000000000000000000000 --- a/district/migrations/0043_auto_20220313_1732.py +++ /dev/null @@ -1,68 +0,0 @@ -# Generated by Django 3.2.11 on 2022-03-13 16:32 -import json - -import wagtail.core.blocks -import wagtail.core.fields -from django.db import migrations -from wagtail.core.rich_text import RichText - - -def convert_data(apps, schema_editor): - DistrictArticlePage = apps.get_model("district", "DistrictArticlePage") - for post in DistrictArticlePage.objects.all(): - # edit the live post - if post.text and not post.content: - post.content = [("text", RichText(post.text))] - post.save() - - # edit drafts associated with post - if post.has_unpublished_changes: - for rev in post.revisions.all(): - data = json.loads(rev.content_json) - text = data["text"] - data["content"] = json.dumps([{"type": "text", "value": text}]) - rev.content_json = json.dumps(data) - rev.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("district", "0042_auto_20220309_1319"), - ] - - operations = [ - migrations.RemoveField( - model_name="districtarticlepage", - name="text", - ), - migrations.RunPython(convert_data), - migrations.AddField( - model_name="districtarticlepage", - name="content", - field=wagtail.core.fields.StreamField( - [ - ( - "text", - wagtail.core.blocks.RichTextBlock( - features=[ - "h2", - "h3", - "h4", - "bold", - "italic", - "ol", - "ul", - "link", - "document-link", - "image", - ], - label="Textový editor", - ), - ) - ], - blank=True, - verbose_name="Článek", - ), - ), - ] diff --git a/district/migrations/0044_remove_districtarticlepage_text_and_more.py b/district/migrations/0044_remove_districtarticlepage_text_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..4059a1e5dffa38caa3b70c409477b3fccb73a38e --- /dev/null +++ b/district/migrations/0044_remove_districtarticlepage_text_and_more.py @@ -0,0 +1,136 @@ +# Generated by Django 4.0.3 on 2022-03-18 09:33 + +# -*- coding: utf-8 -*- +import json + +import wagtail.core.blocks +import wagtail.core.fields +from django.core.serializers.json import DjangoJSONEncoder +from django.db import migrations +from wagtail.core.rich_text import RichText + + +def page_to_streamfield(page): + changed = False + if page.text and not page.content: + page.content = [("text", RichText(page.text))] + changed = True + return page, changed + + +def pagerevision_to_streamfield(revision_data): + changed = False + body = revision_data.get("text") + if body: + try: + json.loads(body) + except ValueError: + revision_data["content"] = json.dumps( + [{"value": body, "type": "text"}], cls=DjangoJSONEncoder + ) + changed = True + else: + # It's already valid JSON. Leave it. + pass + return revision_data, changed + + +def page_to_richtext(page): + changed = False + if page.content.raw_text is None: + raw_text = "".join( + [child.value.source for child in page.content if child.block_type == "text"] + ) + page.text = raw_text + changed = True + return page, changed + + +def pagerevision_to_richtext(revision_data): + changed = False + body = revision_data.get("content", "definitely non-JSON string") + if body: + try: + body_data = json.loads(body) + except ValueError: + # It's not apparently a StreamField. Leave it. + pass + else: + raw_text = "".join( + [child["value"] for child in body_data if child["type"] == "text"] + ) + revision_data["text"] = raw_text + changed = True + return revision_data, changed + + +def convert(apps, schema_editor, page_converter, pagerevision_converter): + DistrictArticlePage = apps.get_model("district", "DistrictArticlePage") + for page in DistrictArticlePage.objects.all(): + + page, changed = page_converter(page) + if changed: + page.save() + + for revision in page.revisions.all(): + revision_data = json.loads(revision.content_json) + revision_data, changed = pagerevision_converter(revision_data) + if changed: + revision.content_json = json.dumps(revision_data, cls=DjangoJSONEncoder) + revision.save() + + +def convert_to_streamfield(apps, schema_editor): + return convert( + apps, schema_editor, page_to_streamfield, pagerevision_to_streamfield + ) + + +def convert_to_richtext(apps, schema_editor): + return convert(apps, schema_editor, page_to_richtext, pagerevision_to_richtext) + + +class Migration(migrations.Migration): + + dependencies = [ + ("district", "0043_alter_districtarticletag_tag_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="districtarticlepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "image", + ], + label="Textový editor", + ), + ) + ], + blank=True, + verbose_name="Článek", + ), + ), + migrations.RunPython( + convert_to_streamfield, + convert_to_richtext, + ), + migrations.RemoveField( + model_name="districtarticlepage", + name="text", + ), + ] diff --git a/elections2021/migrations/0050_auto_20220313_1723.py b/elections2021/migrations/0050_auto_20220313_1723.py deleted file mode 100644 index 71a72d3ff2f5c7607c25eab22e190c7246724a94..0000000000000000000000000000000000000000 --- a/elections2021/migrations/0050_auto_20220313_1723.py +++ /dev/null @@ -1,74 +0,0 @@ -# Generated by Django 3.2.11 on 2022-03-13 16:23 -import json - -import wagtail.core.blocks -import wagtail.core.fields -from django.db import migrations -from wagtail.core.rich_text import RichText - - -def convert_data(apps, schema_editor): - Elections2021ArticlePage = apps.get_model( - "elections2021", "Elections2021ArticlePage" - ) - for post in Elections2021ArticlePage.objects.all(): - # edit the live post - if post.text and not post.content: - post.content = [("text", RichText(post.text))] - post.save() - - # edit drafts associated with post - if post.has_unpublished_changes: - for rev in post.revisions.all(): - data = json.loads(rev.content_json) - text = data["text"] - data["content"] = json.dumps([{"type": "text", "value": text}]) - rev.content_json = json.dumps(data) - rev.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("elections2021", "0049_auto_20210930_2104"), - ] - - operations = [ - migrations.AddField( - model_name="elections2021articlepage", - name="content", - field=wagtail.core.fields.StreamField( - [ - ( - "text", - wagtail.core.blocks.RichTextBlock( - features=[ - "h2", - "h3", - "h4", - "bold", - "italic", - "superscript", - "subscript", - "strikethrough", - "ul-elections2021", - "ol-elections2021", - "blockquote-elections2021", - "link", - "image", - "document-link", - ], - label="Textový editor", - ), - ) - ], - blank=True, - verbose_name="Článek", - ), - ), - migrations.RunPython(convert_data), - migrations.RemoveField( - model_name="elections2021articlepage", - name="text", - ), - ] diff --git a/elections2021/migrations/0051_remove_elections2021articlepage_text_and_more.py b/elections2021/migrations/0051_remove_elections2021articlepage_text_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..7e2a54a37b98973f3d55bef31bb9771e8a7f48b5 --- /dev/null +++ b/elections2021/migrations/0051_remove_elections2021articlepage_text_and_more.py @@ -0,0 +1,142 @@ +# Generated by Django 3.2.11 on 2022-03-13 16:23 + +# -*- coding: utf-8 -*- +import json + +import wagtail.core.blocks +import wagtail.core.fields +from django.core.serializers.json import DjangoJSONEncoder +from django.db import migrations +from wagtail.core.rich_text import RichText + + +def page_to_streamfield(page): + changed = False + if page.text and not page.content: + page.content = [("text", RichText(page.text))] + changed = True + return page, changed + + +def pagerevision_to_streamfield(revision_data): + changed = False + body = revision_data.get("text") + if body: + try: + json.loads(body) + except ValueError: + revision_data["content"] = json.dumps( + [{"value": body, "type": "text"}], cls=DjangoJSONEncoder + ) + changed = True + else: + # It's already valid JSON. Leave it. + pass + return revision_data, changed + + +def page_to_richtext(page): + changed = False + if page.content.raw_text is None: + raw_text = "".join( + [child.value.source for child in page.content if child.block_type == "text"] + ) + page.text = raw_text + changed = True + return page, changed + + +def pagerevision_to_richtext(revision_data): + changed = False + body = revision_data.get("content", "definitely non-JSON string") + if body: + try: + body_data = json.loads(body) + except ValueError: + # It's not apparently a StreamField. Leave it. + pass + else: + raw_text = "".join( + [child["value"] for child in body_data if child["type"] == "text"] + ) + revision_data["text"] = raw_text + changed = True + return revision_data, changed + + +def convert(apps, schema_editor, page_converter, pagerevision_converter): + Elections2021ArticlePage = apps.get_model( + "elections2021", "Elections2021ArticlePage" + ) + for page in Elections2021ArticlePage.objects.all(): + + page, changed = page_converter(page) + if changed: + page.save() + + for revision in page.revisions.all(): + revision_data = json.loads(revision.content_json) + revision_data, changed = pagerevision_converter(revision_data) + if changed: + revision.content_json = json.dumps(revision_data, cls=DjangoJSONEncoder) + revision.save() + + +def convert_to_streamfield(apps, schema_editor): + return convert( + apps, schema_editor, page_to_streamfield, pagerevision_to_streamfield + ) + + +def convert_to_richtext(apps, schema_editor): + return convert(apps, schema_editor, page_to_richtext, pagerevision_to_richtext) + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections2021", "0050_alter_elections2021articletag_tag"), + ] + + operations = [ + migrations.AddField( + model_name="elections2021articlepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "bold", + "italic", + "superscript", + "subscript", + "strikethrough", + "ul-elections2021", + "ol-elections2021", + "blockquote-elections2021", + "link", + "image", + "document-link", + ], + label="Textový editor", + ), + ) + ], + blank=True, + verbose_name="Článek", + ), + ), + migrations.RunPython( + convert_to_streamfield, + convert_to_richtext, + ), + migrations.RemoveField( + model_name="elections2021articlepage", + name="text", + ), + ] diff --git a/region/migrations/0018_regionarticlepage_content.py b/region/migrations/0018_regionarticlepage_content.py deleted file mode 100644 index 7d56101b840b153ee57c0fcccb37a5dd20b42ea2..0000000000000000000000000000000000000000 --- a/region/migrations/0018_regionarticlepage_content.py +++ /dev/null @@ -1,68 +0,0 @@ -# Generated by Django 3.2.11 on 2022-03-13 15:44 -import json - -import wagtail.core.blocks -import wagtail.core.fields -from django.db import migrations -from wagtail.core.rich_text import RichText - - -def convert_data(apps, schema_editor): - RegionArticlePage = apps.get_model("region", "RegionArticlePage") - for post in RegionArticlePage.objects.all(): - # edit the live post - if post.text and not post.content: - post.content = [("text", RichText(post.text))] - post.save() - - # edit drafts associated with post - if post.has_unpublished_changes: - for rev in post.revisions.all(): - data = json.loads(rev.content_json) - text = data["text"] - data["content"] = json.dumps([{"type": "text", "value": text}]) - rev.content_json = json.dumps(data) - rev.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("region", "0017_auto_20220309_1357"), - ] - - operations = [ - migrations.AddField( - model_name="regionarticlepage", - name="content", - field=wagtail.core.fields.StreamField( - [ - ( - "text", - wagtail.core.blocks.RichTextBlock( - features=[ - "h2", - "h3", - "h4", - "bold", - "italic", - "ol", - "ul", - "link", - "document-link", - "image", - ], - label="Textový editor", - ), - ) - ], - blank=True, - verbose_name="Článek", - ), - ), - migrations.RunPython(convert_data), - migrations.RemoveField( - model_name="regionarticlepage", - name="text", - ), - ] diff --git a/region/migrations/0019_remove_regionarticlepage_text_and_more.py b/region/migrations/0019_remove_regionarticlepage_text_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..60cf751d47817e35abcb04766e35e79d2dc303c5 --- /dev/null +++ b/region/migrations/0019_remove_regionarticlepage_text_and_more.py @@ -0,0 +1,136 @@ +# Generated by Django 3.2.11 on 2022-03-13 15:44 + +# -*- coding: utf-8 -*- +import json + +import wagtail.core.blocks +import wagtail.core.fields +from django.core.serializers.json import DjangoJSONEncoder +from django.db import migrations +from wagtail.core.rich_text import RichText + + +def page_to_streamfield(page): + changed = False + if page.text and not page.content: + page.content = [("text", RichText(page.text))] + changed = True + return page, changed + + +def pagerevision_to_streamfield(revision_data): + changed = False + body = revision_data.get("text") + if body: + try: + json.loads(body) + except ValueError: + revision_data["content"] = json.dumps( + [{"value": body, "type": "text"}], cls=DjangoJSONEncoder + ) + changed = True + else: + # It's already valid JSON. Leave it. + pass + return revision_data, changed + + +def page_to_richtext(page): + changed = False + if page.content.raw_text is None: + raw_text = "".join( + [child.value.source for child in page.content if child.block_type == "text"] + ) + page.text = raw_text + changed = True + return page, changed + + +def pagerevision_to_richtext(revision_data): + changed = False + body = revision_data.get("content", "definitely non-JSON string") + if body: + try: + body_data = json.loads(body) + except ValueError: + # It's not apparently a StreamField. Leave it. + pass + else: + raw_text = "".join( + [child["value"] for child in body_data if child["type"] == "text"] + ) + revision_data["text"] = raw_text + changed = True + return revision_data, changed + + +def convert(apps, schema_editor, page_converter, pagerevision_converter): + RegionArticlePage = apps.get_model("region", "RegionArticlePage") + for page in RegionArticlePage.objects.all(): + + page, changed = page_converter(page) + if changed: + page.save() + + for revision in page.revisions.all(): + revision_data = json.loads(revision.content_json) + revision_data, changed = pagerevision_converter(revision_data) + if changed: + revision.content_json = json.dumps(revision_data, cls=DjangoJSONEncoder) + revision.save() + + +def convert_to_streamfield(apps, schema_editor): + return convert( + apps, schema_editor, page_to_streamfield, pagerevision_to_streamfield + ) + + +def convert_to_richtext(apps, schema_editor): + return convert(apps, schema_editor, page_to_richtext, pagerevision_to_richtext) + + +class Migration(migrations.Migration): + + dependencies = [ + ("region", "0018_alter_regionarticletag_tag_alter_regionpersontag_tag"), + ] + + operations = [ + migrations.AddField( + model_name="regionarticlepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "image", + ], + label="Textový editor", + ), + ) + ], + blank=True, + verbose_name="Článek", + ), + ), + migrations.RunPython( + convert_to_streamfield, + convert_to_richtext, + ), + migrations.RemoveField( + model_name="regionarticlepage", + name="text", + ), + ] diff --git a/shared/models.py b/shared/models.py index d9d2ac50bd8957078b23eed66ba1eab9a7be9201..d070cf939bfb1bcc68ebeace4dd102e27d9fe2cb 100644 --- a/shared/models.py +++ b/shared/models.py @@ -53,7 +53,6 @@ class ArticleMixin(models.Model): ) date = models.DateField("datum", default=timezone.now) perex = models.TextField("perex") - # text = RichTextField("článek", blank=True, features=RICH_TEXT_FEATURES) author = models.CharField("autor", max_length=250, blank=True, null=True) image = models.ForeignKey( "wagtailimages.Image", @@ -68,7 +67,6 @@ class ArticleMixin(models.Model): content_panels = Page.content_panels + [ FieldPanel("date"), FieldPanel("perex"), - # FieldPanel("text"), StreamFieldPanel("content"), FieldPanel("author"), ImageChooserPanel("image"), diff --git a/uniweb/migrations/0021_auto_20220313_1719.py b/uniweb/migrations/0021_auto_20220313_1719.py deleted file mode 100644 index d21c077fbfcf5bfafaca37f4ffbba256ee0c1115..0000000000000000000000000000000000000000 --- a/uniweb/migrations/0021_auto_20220313_1719.py +++ /dev/null @@ -1,68 +0,0 @@ -# Generated by Django 3.2.11 on 2022-03-13 16:19 -import json - -import wagtail.core.blocks -import wagtail.core.fields -from django.db import migrations -from wagtail.core.rich_text import RichText - - -def convert_data(apps, schema_editor): - UniwebArticlePage = apps.get_model("uniweb", "UniwebArticlePage") - for post in UniwebArticlePage.objects.all(): - # edit the live post - if post.text and not post.content: - post.content = [("text", RichText(post.text))] - post.save() - - # edit drafts associated with post - if post.has_unpublished_changes: - for rev in post.revisions.all(): - data = json.loads(rev.content_json) - text = data["text"] - data["content"] = json.dumps([{"type": "text", "value": text}]) - rev.content_json = json.dumps(data) - rev.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("uniweb", "0020_auto_20220213_1210"), - ] - - operations = [ - migrations.AddField( - model_name="uniwebarticlepage", - name="content", - field=wagtail.core.fields.StreamField( - [ - ( - "text", - wagtail.core.blocks.RichTextBlock( - features=[ - "h2", - "h3", - "h4", - "bold", - "italic", - "ol", - "ul", - "link", - "document-link", - "image", - ], - label="Textový editor", - ), - ) - ], - blank=True, - verbose_name="Článek", - ), - ), - migrations.RunPython(convert_data), - migrations.RemoveField( - model_name="uniwebarticlepage", - name="text", - ), - ] diff --git a/uniweb/migrations/0022_remove_uniwebarticlepage_text_and_more.py b/uniweb/migrations/0022_remove_uniwebarticlepage_text_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..c7bcc10f9c6c36f4758a9e616444c1abcfb8aaa1 --- /dev/null +++ b/uniweb/migrations/0022_remove_uniwebarticlepage_text_and_more.py @@ -0,0 +1,136 @@ +# Generated by Django 3.2.11 on 2022-03-13 16:19 + +# -*- coding: utf-8 -*- +import json + +import wagtail.core.blocks +import wagtail.core.fields +from django.core.serializers.json import DjangoJSONEncoder +from django.db import migrations +from wagtail.core.rich_text import RichText + + +def page_to_streamfield(page): + changed = False + if page.text and not page.content: + page.content = [("text", RichText(page.text))] + changed = True + return page, changed + + +def pagerevision_to_streamfield(revision_data): + changed = False + body = revision_data.get("text") + if body: + try: + json.loads(body) + except ValueError: + revision_data["content"] = json.dumps( + [{"value": body, "type": "text"}], cls=DjangoJSONEncoder + ) + changed = True + else: + # It's already valid JSON. Leave it. + pass + return revision_data, changed + + +def page_to_richtext(page): + changed = False + if page.content.raw_text is None: + raw_text = "".join( + [child.value.source for child in page.content if child.block_type == "text"] + ) + page.text = raw_text + changed = True + return page, changed + + +def pagerevision_to_richtext(revision_data): + changed = False + body = revision_data.get("content", "definitely non-JSON string") + if body: + try: + body_data = json.loads(body) + except ValueError: + # It's not apparently a StreamField. Leave it. + pass + else: + raw_text = "".join( + [child["value"] for child in body_data if child["type"] == "text"] + ) + revision_data["text"] = raw_text + changed = True + return revision_data, changed + + +def convert(apps, schema_editor, page_converter, pagerevision_converter): + UniwebArticlePage = apps.get_model("uniweb", "UniwebArticlePage") + for page in UniwebArticlePage.objects.all(): + + page, changed = page_converter(page) + if changed: + page.save() + + for revision in page.revisions.all(): + revision_data = json.loads(revision.content_json) + revision_data, changed = pagerevision_converter(revision_data) + if changed: + revision.content_json = json.dumps(revision_data, cls=DjangoJSONEncoder) + revision.save() + + +def convert_to_streamfield(apps, schema_editor): + return convert( + apps, schema_editor, page_to_streamfield, pagerevision_to_streamfield + ) + + +def convert_to_richtext(apps, schema_editor): + return convert(apps, schema_editor, page_to_richtext, pagerevision_to_richtext) + + +class Migration(migrations.Migration): + + dependencies = [ + ("uniweb", "0021_alter_uniwebarticletag_tag"), + ] + + operations = [ + migrations.AddField( + model_name="uniwebarticlepage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "text", + wagtail.core.blocks.RichTextBlock( + features=[ + "h2", + "h3", + "h4", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "image", + ], + label="Textový editor", + ), + ) + ], + blank=True, + verbose_name="Článek", + ), + ), + migrations.RunPython( + convert_to_streamfield, + convert_to_richtext, + ), + migrations.RemoveField( + model_name="uniwebarticlepage", + name="text", + ), + ]