Skip to content

Commit

Permalink
Content warning changes (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs authored Feb 10, 2025
1 parent e1b092a commit 50e1fb1
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 29 deletions.
1 change: 0 additions & 1 deletion etna/api/tests/expected_results/article.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
"is_sensitive": false,
"custom_sensitive_image_warning": null
},
"display_content_warning": false,
"custom_warning_text": "",
"tags": [
"Witchcraft"
Expand Down
1 change: 0 additions & 1 deletion etna/api/tests/expected_results/focused_article.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
"is_sensitive": false,
"custom_sensitive_image_warning": null
},
"display_content_warning": false,
"custom_warning_text": "",
"tags": [
"Medicine",
Expand Down
1 change: 0 additions & 1 deletion etna/api/tests/expected_results/highlight_gallery.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"message": "<p>Test message</p>"
},
"intro": "<p>Intro text</p>",
"display_content_warning": false,
"custom_warning_text": "",
"featured_article": {
"id": ARTICLE_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)'),
),
]
Original file line number Diff line number Diff line change
@@ -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)'),
),
]
Original file line number Diff line number Diff line change
@@ -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)'),
),
]
22 changes: 3 additions & 19 deletions etna/core/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]

Expand Down
2 changes: 1 addition & 1 deletion templates/articles/article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

<div class="article-container__main tna-column tna-column--width-3-4 tna-column--full-small tna-column--full-tiny">
{% 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 %}
Expand Down
2 changes: 1 addition & 1 deletion templates/articles/focused_article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="tna-container">
<div class="tna-column tna-column--width-3-4 tna-column--width-2-3-medium tna-column--full-small tna-column--full-tiny">
<div class="article-container__main">
{% 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 %}

Expand Down
2 changes: 1 addition & 1 deletion templates/articles/record_article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion templates/collections/highlight_gallery_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion templates/includes/generic-intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 class="tna-heading-xl tna-!--margin-top-l">
{% 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 %}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/includes/record-revealed-intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ <h1 class="tna-hgroup__title">
{{ page.title }}
</h1>
</hgroup>
<div class="explore-intro__paragraph{% if display_content_warning %} explore-intro__paragraph--short{% endif %} tna-!--margin-vertical-m">{{ page.intro|richtext }}</div>
{% if display_content_warning %}
<div class="explore-intro__paragraph{% if custom_warning_text %} explore-intro__paragraph--short{% endif %} tna-!--margin-vertical-m">{{ page.intro|richtext }}</div>
{% if custom_warning_text %}
{% include "includes/content-warning.html" with custom_warning_text=custom_warning_text %}
{% endif %}
</div>
Expand Down

0 comments on commit 50e1fb1

Please sign in to comment.