Skip to content

Commit 443d669

Browse files
committed
setup ContentWarningMessage
1 parent d5e51c7 commit 443d669

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 5.0.6 on 2024-06-25 00:06
2+
3+
import django.db.models.deletion
4+
import uuid
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
("snippets", "0035_alter_k12subject_subject_color_and_more"),
12+
("wagtailcore", "0089_log_entry_data_json_null_to_object"),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name="ContentWarningMessage",
18+
fields=[
19+
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
20+
("translation_key", models.UUIDField(default=uuid.uuid4, editable=False)),
21+
("content_warning_message", models.TextField()),
22+
(
23+
"locale",
24+
models.ForeignKey(
25+
editable=False,
26+
on_delete=django.db.models.deletion.PROTECT,
27+
related_name="+",
28+
to="wagtailcore.locale",
29+
),
30+
),
31+
],
32+
options={
33+
"abstract": False,
34+
"unique_together": {("translation_key", "locale")},
35+
},
36+
),
37+
]

snippets/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,17 @@ def __str__(self):
485485

486486

487487
register_snippet(AmazonBookBlurb)
488+
489+
class ContentWarningMessage(TranslatableMixin, models.Model):
490+
content_warning_message = models.TextField()
491+
492+
api_fields = ('content_warning_message')
493+
494+
panels = [
495+
FieldPanel('content_warning_message')
496+
]
497+
498+
def __str__(self):
499+
return 'content_warning_message'
500+
501+
register_snippet(ContentWarningMessage)

snippets/serializers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .models import Role, Subject, K12Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, \
2-
BlogCollection, NoWebinarMessage, WebinarCollection, AmazonBookBlurb
2+
BlogCollection, NoWebinarMessage, WebinarCollection, AmazonBookBlurb, ContentWarningMessage
33

44

55
from rest_framework import serializers, generics
@@ -39,11 +39,11 @@ class K12SubjectSerializer(serializers.ModelSerializer):
3939
class Meta:
4040
model = K12Subject
4141
fields = ('id',
42-
'name',
43-
'intro_text',
44-
'subject_image',
45-
'subject_category' ,
46-
'subject_color',
42+
'name',
43+
'intro_text',
44+
'subject_image',
45+
'subject_category' ,
46+
'subject_color',
4747
'subject_link'
4848
)
4949
read_only_fields = ('id',
@@ -133,4 +133,8 @@ class Meta:
133133
fields = ('amazon_book_blurb',)
134134
read_only_fields = ('amazon_book_blurb',)
135135

136-
136+
class ContentWarningMessageSerializer(serializers.ModelSerializer):
137+
class Meta:
138+
model = ContentWarningMessage
139+
fields = ('content_warning_message',)
140+
read_only_fields = ('content_warning_message',)

snippets/signals.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.dispatch import receiver
33

44
from global_settings.functions import invalidate_cloudfront_caches
5-
from snippets.models import Subject, Role, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, \
5+
from snippets.models import ContentWarningMessage, Subject, Role, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, \
66
WebinarCollection, AmazonBookBlurb, PromoteSnippet
77

88

@@ -53,3 +53,6 @@ def clear_cloudfront_on_assignable_available_save(sender, **kwargs):
5353
def clear_cloudfront_on_amazon_book_blurb_save(sender, **kwargs):
5454
invalidate_cloudfront_caches('snippets/amazonbookblurb')
5555

56+
@receiver(post_save, sender=ContentWarningMessage)
57+
def clear_cloudfront_on_content_warning_message_save(sender, **kwargs):
58+
invalidate_cloudfront_caches('snippets/contentwarningmessage')

snippets/tests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.conf import settings
77
from django.urls import reverse
88

9-
from snippets.models import Subject, ErrataContent, GiveBanner, BlogContentType, NoWebinarMessage, K12Subject, \
9+
from snippets.models import ContentWarningMessage, Subject, ErrataContent, GiveBanner, BlogContentType, NoWebinarMessage, K12Subject, \
1010
FacultyResource, StudentResource, Role, SharedContent, NewsSource, SubjectCategory, BlogCollection, \
1111
AmazonBookBlurb, PromoteSnippet
1212

@@ -72,6 +72,10 @@ def setUp(self):
7272
amazon_book_blurb="Amazon Book Blurb. Amazon Book Blurb. Amazon Book Blurb.")
7373
self.amazon_book_blurb.save()
7474

75+
self.content_warning_message = ContentWarningMessage(
76+
content_warning_message = "Content Warning Message")
77+
self.content_warning_message.save()
78+
7579

7680
def test_can_create_subject(self):
7781
subject = Subject(name="Science", page_content="Science page content.", seo_title="Science SEO Title",
@@ -151,4 +155,3 @@ def test_can_create_promote_snippet(self):
151155
promote_snippet.save()
152156

153157
self.assertEqual(promote_snippet.name, "Assignable")
154-

0 commit comments

Comments
 (0)