Skip to content

Commit

Permalink
DSRC-102: Mourning notice (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs authored Jul 30, 2024
1 parent bcc549c commit 1948195
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 5 deletions.
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/article.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>This is an article with <a href=\"/\">a link to a page</a><page>",
"hero_image_caption": "<p>Hero image caption</p>",
"hero_image": {
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/article_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"featured_article": {
"id": ARTICLE_ID,
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/arts.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"body": [],
"featured_article": null,
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/author.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"role": "Test Author",
"summary": "<p>Summary text</p>",
"authored_focused_articles": [
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/authors.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"author_pages": [
{
"id": AUTHOR_ID,
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/early_modern.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"body": [],
"featured_article": null,
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/focused_article.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"hero_image_caption": "<p>Hero image caption</p>",
"hero_image": {
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/highlight_gallery.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"display_content_warning": false,
"custom_warning_text": "",
Expand Down
5 changes: 5 additions & 0 deletions etna/api/tests/expected_results/postwar.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
},
"facebook_og_image": null,
"twitter_og_image": null,
"mourning_notice": {
"name": "John Smith",
"birth_date": "1 January 1900",
"death_date": "1 January 2000"
},
"intro": "<p>Intro text</p>",
"body": [],
"featured_article": null,
Expand Down
10 changes: 10 additions & 0 deletions etna/api/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
TopicPageFactory,
)
from etna.collections.models import Highlight, PageTimePeriod, PageTopic
from etna.home.models import MourningNotice
from etna.media.models import EtnaMedia

API_URL = "/api/v2/pages/"
Expand Down Expand Up @@ -53,6 +54,15 @@ class APIResponseTest(WagtailPageTestCase):
@classmethod
def setUpTestData(cls):
cls.root_page = Site.objects.get().root_page
cls.root_page.mourning = [
MourningNotice.objects.create(
name="John Smith",
birth_date="1 January 1900",
death_date="1 January 2000",
page=cls.root_page,
page_id=cls.root_page.id,
)
]

cls.test_image = ImageFactory(
transcription="<p>Transcript</p>",
Expand Down
13 changes: 12 additions & 1 deletion etna/core/models/basepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
apply_default_cache_control,
apply_default_vary_headers,
)
from etna.core.serializers import ImageSerializer, RichTextSerializer
from etna.core.serializers import (
ImageSerializer,
MourningSerializer,
RichTextSerializer,
)

__all__ = [
"BasePage",
Expand Down Expand Up @@ -158,6 +162,12 @@ def privacy(self):
return privacy[0]
return "public"

@property
def mourning_notice(self):
from etna.home.models import MourningNotice

return MourningNotice.objects.first()

default_api_fields = [
APIField("id"),
APIField("title"),
Expand Down Expand Up @@ -190,6 +200,7 @@ def privacy(self):
"twitter_og_image",
serializer=ImageSerializer("fill-1200x600", source="search_image"),
),
APIField("mourning_notice", serializer=MourningSerializer()),
]


Expand Down
5 changes: 3 additions & 2 deletions etna/core/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .images import DetailedImageSerializer, HighlightImageSerializer, ImageSerializer
from .pages import DefaultPageSerializer
from .richtext import RichTextSerializer
from .tags import TaggableSerializer
from .tags import MourningSerializer, TaggableSerializer

__all__ = [
"DefaultPageSerializer",
"DetailedImageSerializer",
"ImageSerializer",
"HighlightImageSerializer",
"ImageSerializer",
"MourningSerializer",
"RichTextSerializer",
"TaggableSerializer",
]
9 changes: 9 additions & 0 deletions etna/core/serializers/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ class TaggableSerializer(serializers.CharField):

def to_representation(self, instance):
return [tag.name for tag in instance.all()]


class MourningSerializer(serializers.Serializer):
def to_representation(self, instance):
return {
"name": instance.name,
"birth_date": instance.birth_date,
"death_date": instance.death_date,
}
41 changes: 41 additions & 0 deletions etna/home/migrations/0027_mourningnotice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.0.7 on 2024-07-30 07:34

import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("home", "0026_alter_homepage_body"),
("wagtailcore", "0093_uploadedfile"),
]

operations = [
migrations.CreateModel(
name="MourningNotice",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("birth_date", models.CharField()),
("death_date", models.CharField()),
(
"page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="mourning",
to="wagtailcore.page",
),
),
],
),
]
27 changes: 26 additions & 1 deletion etna/home/models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
from wagtail.admin.panels import FieldPanel
from django.db import models

from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel
from wagtail.api import APIField
from wagtail.fields import StreamField
from wagtail.models import Page

from etna.core.models import BasePageWithRequiredIntro

from .blocks import HomePageStreamBlock


class MourningNotice(models.Model):
"""
A model to hold mourning notice information.
"""

page = ParentalKey(Page, on_delete=models.CASCADE, related_name="mourning")
name = models.CharField(max_length=255)
birth_date = models.CharField()
death_date = models.CharField()

panels = [
FieldPanel("name"),
FieldPanel("birth_date"),
FieldPanel("death_date"),
]


class HomePage(BasePageWithRequiredIntro):
body = StreamField(HomePageStreamBlock, blank=True, null=True)

content_panels = BasePageWithRequiredIntro.content_panels + [
FieldPanel("body"),
]

settings_panels = BasePageWithRequiredIntro.settings_panels + [
InlinePanel("mourning", label="Mourning Notice", max_num=1),
]

# DataLayerMixin overrides
gtm_content_group = "Homepage"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.7 on 2024-07-30 08:36
# etna:allowAlterField

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("images", "0008_alter_customimagerendition_file"),
]

operations = [
migrations.AlterField(
model_name="customimage",
name="custom_sensitive_image_warning",
field=models.CharField(
blank=True,
help_text='Replaces the default warning message where the image is displayed. For example: "This image has been marked as potentially sensitive because it contains depictions of violence".',
max_length=200,
verbose_name="Why might this image be considered sensitive? (optional)",
),
),
]
2 changes: 1 addition & 1 deletion etna/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CustomImage(ClusterableModel, AbstractImage):
),
)

custom_sensitive_image_warning = models.TextField(
custom_sensitive_image_warning = models.CharField(
verbose_name=_("Why might this image be considered sensitive? (optional)"),
help_text=_(
'Replaces the default warning message where the image is displayed. For example: "This image has been marked as potentially sensitive because it contains depictions of violence".'
Expand Down

0 comments on commit 1948195

Please sign in to comment.