From 50e1fb1d36d1629cd12ee662c254076e402e91b7 Mon Sep 17 00:00:00 2001 From: James Biggs <62654785+jamesbiggs@users.noreply.github.com> Date: Mon, 10 Feb 2025 12:56:10 +0000 Subject: [PATCH] Content warning changes (#1795) --- etna/api/tests/expected_results/article.json | 1 - .../expected_results/focused_article.json | 1 - .../expected_results/highlight_gallery.json | 1 - ...lepage_display_content_warning_and_more.py | 43 +++++++++++++++++++ ...stpage_display_content_warning_and_more.py | 25 +++++++++++ ...rypage_display_content_warning_and_more.py | 25 +++++++++++ etna/core/models/mixins.py | 22 ++-------- templates/articles/article_page.html | 2 +- templates/articles/focused_article_page.html | 2 +- templates/articles/record_article_page.html | 2 +- .../collections/highlight_gallery_page.html | 2 +- templates/includes/generic-intro.html | 2 +- templates/includes/record-revealed-intro.html | 4 +- 13 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 etna/articles/migrations/0117_remove_articlepage_display_content_warning_and_more.py create mode 100644 etna/blog/migrations/0015_remove_blogpostpage_display_content_warning_and_more.py create mode 100644 etna/collections/migrations/0062_remove_highlightgallerypage_display_content_warning_and_more.py diff --git a/etna/api/tests/expected_results/article.json b/etna/api/tests/expected_results/article.json index 32033d1ff..0d5af07c4 100644 --- a/etna/api/tests/expected_results/article.json +++ b/etna/api/tests/expected_results/article.json @@ -113,7 +113,6 @@ "is_sensitive": false, "custom_sensitive_image_warning": null }, - "display_content_warning": false, "custom_warning_text": "", "tags": [ "Witchcraft" diff --git a/etna/api/tests/expected_results/focused_article.json b/etna/api/tests/expected_results/focused_article.json index 95f03e6d6..51b821198 100644 --- a/etna/api/tests/expected_results/focused_article.json +++ b/etna/api/tests/expected_results/focused_article.json @@ -113,7 +113,6 @@ "is_sensitive": false, "custom_sensitive_image_warning": null }, - "display_content_warning": false, "custom_warning_text": "", "tags": [ "Medicine", diff --git a/etna/api/tests/expected_results/highlight_gallery.json b/etna/api/tests/expected_results/highlight_gallery.json index 9929e324e..ef261c1e0 100644 --- a/etna/api/tests/expected_results/highlight_gallery.json +++ b/etna/api/tests/expected_results/highlight_gallery.json @@ -70,7 +70,6 @@ "message": "

Test message

" }, "intro": "

Intro text

", - "display_content_warning": false, "custom_warning_text": "", "featured_article": { "id": ARTICLE_ID, diff --git a/etna/articles/migrations/0117_remove_articlepage_display_content_warning_and_more.py b/etna/articles/migrations/0117_remove_articlepage_display_content_warning_and_more.py new file mode 100644 index 000000000..7a06f9d5d --- /dev/null +++ b/etna/articles/migrations/0117_remove_articlepage_display_content_warning_and_more.py @@ -0,0 +1,43 @@ +# Generated by Django 5.1.5 on 2025-02-10 08:55 +# etna:allowAlterField +# etna:allowRemoveField + +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('articles', '0116_articleindexpage_short_title_articlepage_short_title_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='articlepage', + name='display_content_warning', + ), + migrations.RemoveField( + model_name='focusedarticlepage', + name='display_content_warning', + ), + migrations.RemoveField( + model_name='recordarticlepage', + name='display_content_warning', + ), + migrations.AlterField( + model_name='articlepage', + name='custom_warning_text', + field=wagtail.fields.RichTextField(blank=True, help_text='If specified, will be used for the content warning.', verbose_name='custom content warning text (optional)'), + ), + migrations.AlterField( + model_name='focusedarticlepage', + name='custom_warning_text', + field=wagtail.fields.RichTextField(blank=True, help_text='If specified, will be used for the content warning.', verbose_name='custom content warning text (optional)'), + ), + migrations.AlterField( + model_name='recordarticlepage', + name='custom_warning_text', + field=wagtail.fields.RichTextField(blank=True, help_text='If specified, will be used for the content warning.', verbose_name='custom content warning text (optional)'), + ), + ] diff --git a/etna/blog/migrations/0015_remove_blogpostpage_display_content_warning_and_more.py b/etna/blog/migrations/0015_remove_blogpostpage_display_content_warning_and_more.py new file mode 100644 index 000000000..45068775d --- /dev/null +++ b/etna/blog/migrations/0015_remove_blogpostpage_display_content_warning_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.5 on 2025-02-10 08:55 +# etna:allowAlterField +# etna:allowRemoveField + +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0014_alter_blogpostpage_body'), + ] + + operations = [ + migrations.RemoveField( + model_name='blogpostpage', + name='display_content_warning', + ), + migrations.AlterField( + model_name='blogpostpage', + name='custom_warning_text', + field=wagtail.fields.RichTextField(blank=True, help_text='If specified, will be used for the content warning.', verbose_name='custom content warning text (optional)'), + ), + ] diff --git a/etna/collections/migrations/0062_remove_highlightgallerypage_display_content_warning_and_more.py b/etna/collections/migrations/0062_remove_highlightgallerypage_display_content_warning_and_more.py new file mode 100644 index 000000000..39ac78d42 --- /dev/null +++ b/etna/collections/migrations/0062_remove_highlightgallerypage_display_content_warning_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.5 on 2025-02-10 08:55 +# etna:allowAlterField +# etna:allowRemoveField + +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('collections', '0061_explorerindexpage_short_title_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='highlightgallerypage', + name='display_content_warning', + ), + migrations.AlterField( + model_name='highlightgallerypage', + name='custom_warning_text', + field=wagtail.fields.RichTextField(blank=True, help_text='If specified, will be used for the content warning.', verbose_name='custom content warning text (optional)'), + ), + ] diff --git a/etna/core/models/mixins.py b/etna/core/models/mixins.py index d1ea9012e..d0db53cd0 100644 --- a/etna/core/models/mixins.py +++ b/etna/core/models/mixins.py @@ -34,36 +34,20 @@ class ContentWarningMixin(models.Model): - """Mixin to allow editors to toggle content warnings on and off""" - - display_content_warning = models.BooleanField( - verbose_name="display a content warning on this page", - default=False, - ) + """Mixin to allow editors to add content warnings to a page.""" custom_warning_text = RichTextField( verbose_name="custom content warning text (optional)", features=["link"], blank=True, - help_text=( - "If specified, will be used for the content warning. " - "Otherwise the default text will be used." - ), + help_text=("If specified, will be used for the content warning."), ) content_panels = [ - MultiFieldPanel( - [ - FieldPanel("display_content_warning"), - FieldPanel("custom_warning_text"), - ], - heading="Content Warning Options", - classname="collapsible", - ), + FieldPanel("custom_warning_text"), ] api_fields = [ - APIField("display_content_warning"), APIField("custom_warning_text", serializer=RichTextSerializer()), ] diff --git a/templates/articles/article_page.html b/templates/articles/article_page.html index 8755d60f2..b43e072ca 100644 --- a/templates/articles/article_page.html +++ b/templates/articles/article_page.html @@ -13,7 +13,7 @@
- {% if page.display_content_warning %} + {% if page.custom_warning_text %} {% include "includes/content-warning.html" with custom_warning_text=page.custom_warning_text classes="content-warning--short content-warning--normalise-article-margin" %} {% endif %} {% for block in page.body %} diff --git a/templates/articles/focused_article_page.html b/templates/articles/focused_article_page.html index 2555342f5..f28eb651e 100644 --- a/templates/articles/focused_article_page.html +++ b/templates/articles/focused_article_page.html @@ -45,7 +45,7 @@
- {% if page.display_content_warning %} + {% if page.custom_warning_text %} {% include "includes/content-warning.html" with custom_warning_text=page.custom_warning_text classes="content-warning--short content-warning--normalise-article-margin" %} {% endif %} diff --git a/templates/articles/record_article_page.html b/templates/articles/record_article_page.html index 5f0fb109b..9aa5b96aa 100644 --- a/templates/articles/record_article_page.html +++ b/templates/articles/record_article_page.html @@ -3,7 +3,7 @@ {% load static wagtailcore_tags sections_tags %} {% block content %} - {% include "includes/record-revealed-intro.html" with display_content_warning=page.display_content_warning custom_warning_text=page.custom_warning_text %} + {% include "includes/record-revealed-intro.html" with custom_warning_text=page.custom_warning_text %} {% if page.gallery_items %} {% include "includes/image_gallery.html" with gallery=page.gallery_items has_text=page.gallery_has_translations_transcriptions %} {% endif %} diff --git a/templates/collections/highlight_gallery_page.html b/templates/collections/highlight_gallery_page.html index 0ad929699..0963587f0 100644 --- a/templates/collections/highlight_gallery_page.html +++ b/templates/collections/highlight_gallery_page.html @@ -3,7 +3,7 @@ {% load i18n static wagtailcore_tags wagtailimages_tags records_tags %} {% block content %} - {% include "includes/generic-intro.html" with title=page.title intro=page.intro display_content_warning=page.display_content_warning custom_warning_text=page.custom_warning_text %} + {% include "includes/generic-intro.html" with title=page.title intro=page.intro custom_warning_text=page.custom_warning_text %} {% if page.highlights %} {% include 'includes/highlights-gallery.html' with highlights=page.highlights %} diff --git a/templates/includes/generic-intro.html b/templates/includes/generic-intro.html index 031a56d5f..305537ac6 100644 --- a/templates/includes/generic-intro.html +++ b/templates/includes/generic-intro.html @@ -17,7 +17,7 @@

{% if intro %} {{ intro|richtext }} {% endif %} - {% if display_content_warning %} + {% if custom_warning_text %} {% include "includes/content-warning.html" with custom_warning_text=custom_warning_text classes=classes %} {% endif %}

diff --git a/templates/includes/record-revealed-intro.html b/templates/includes/record-revealed-intro.html index 7a035414c..35826ee7b 100644 --- a/templates/includes/record-revealed-intro.html +++ b/templates/includes/record-revealed-intro.html @@ -8,8 +8,8 @@

{{ page.title }}

-
{{ page.intro|richtext }}
- {% if display_content_warning %} +
{{ page.intro|richtext }}
+ {% if custom_warning_text %} {% include "includes/content-warning.html" with custom_warning_text=custom_warning_text %} {% endif %}