From 443d669da00ece5e523253cded27dc9ad3fbe41a Mon Sep 17 00:00:00 2001 From: Josiah Ivey Date: Mon, 24 Jun 2024 17:22:31 -0700 Subject: [PATCH] setup ContentWarningMessage --- .../migrations/0036_contentwarningmessage.py | 37 +++++++++++++++++++ snippets/models.py | 14 +++++++ snippets/serializers.py | 18 +++++---- snippets/signals.py | 5 ++- snippets/tests.py | 7 +++- 5 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 snippets/migrations/0036_contentwarningmessage.py diff --git a/snippets/migrations/0036_contentwarningmessage.py b/snippets/migrations/0036_contentwarningmessage.py new file mode 100644 index 000000000..5c469de5d --- /dev/null +++ b/snippets/migrations/0036_contentwarningmessage.py @@ -0,0 +1,37 @@ +# Generated by Django 5.0.6 on 2024-06-25 00:06 + +import django.db.models.deletion +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("snippets", "0035_alter_k12subject_subject_color_and_more"), + ("wagtailcore", "0089_log_entry_data_json_null_to_object"), + ] + + operations = [ + migrations.CreateModel( + name="ContentWarningMessage", + fields=[ + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("translation_key", models.UUIDField(default=uuid.uuid4, editable=False)), + ("content_warning_message", models.TextField()), + ( + "locale", + models.ForeignKey( + editable=False, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailcore.locale", + ), + ), + ], + options={ + "abstract": False, + "unique_together": {("translation_key", "locale")}, + }, + ), + ] diff --git a/snippets/models.py b/snippets/models.py index 9e43b85ce..cdd8482ba 100644 --- a/snippets/models.py +++ b/snippets/models.py @@ -485,3 +485,17 @@ def __str__(self): register_snippet(AmazonBookBlurb) + +class ContentWarningMessage(TranslatableMixin, models.Model): + content_warning_message = models.TextField() + + api_fields = ('content_warning_message') + + panels = [ + FieldPanel('content_warning_message') + ] + + def __str__(self): + return 'content_warning_message' + +register_snippet(ContentWarningMessage) diff --git a/snippets/serializers.py b/snippets/serializers.py index c60b2fee7..23fd1514b 100644 --- a/snippets/serializers.py +++ b/snippets/serializers.py @@ -1,5 +1,5 @@ from .models import Role, Subject, K12Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, \ - BlogCollection, NoWebinarMessage, WebinarCollection, AmazonBookBlurb + BlogCollection, NoWebinarMessage, WebinarCollection, AmazonBookBlurb, ContentWarningMessage from rest_framework import serializers, generics @@ -39,11 +39,11 @@ class K12SubjectSerializer(serializers.ModelSerializer): class Meta: model = K12Subject fields = ('id', - 'name', - 'intro_text', - 'subject_image', - 'subject_category' , - 'subject_color', + 'name', + 'intro_text', + 'subject_image', + 'subject_category' , + 'subject_color', 'subject_link' ) read_only_fields = ('id', @@ -133,4 +133,8 @@ class Meta: fields = ('amazon_book_blurb',) read_only_fields = ('amazon_book_blurb',) - +class ContentWarningMessageSerializer(serializers.ModelSerializer): + class Meta: + model = ContentWarningMessage + fields = ('content_warning_message',) + read_only_fields = ('content_warning_message',) diff --git a/snippets/signals.py b/snippets/signals.py index 2def15780..78d762cc4 100644 --- a/snippets/signals.py +++ b/snippets/signals.py @@ -2,7 +2,7 @@ from django.dispatch import receiver from global_settings.functions import invalidate_cloudfront_caches -from snippets.models import Subject, Role, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, \ +from snippets.models import ContentWarningMessage, Subject, Role, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, \ WebinarCollection, AmazonBookBlurb, PromoteSnippet @@ -53,3 +53,6 @@ def clear_cloudfront_on_assignable_available_save(sender, **kwargs): def clear_cloudfront_on_amazon_book_blurb_save(sender, **kwargs): invalidate_cloudfront_caches('snippets/amazonbookblurb') +@receiver(post_save, sender=ContentWarningMessage) +def clear_cloudfront_on_content_warning_message_save(sender, **kwargs): + invalidate_cloudfront_caches('snippets/contentwarningmessage') diff --git a/snippets/tests.py b/snippets/tests.py index c08b51990..4855af9e8 100644 --- a/snippets/tests.py +++ b/snippets/tests.py @@ -6,7 +6,7 @@ from django.conf import settings from django.urls import reverse -from snippets.models import Subject, ErrataContent, GiveBanner, BlogContentType, NoWebinarMessage, K12Subject, \ +from snippets.models import ContentWarningMessage, Subject, ErrataContent, GiveBanner, BlogContentType, NoWebinarMessage, K12Subject, \ FacultyResource, StudentResource, Role, SharedContent, NewsSource, SubjectCategory, BlogCollection, \ AmazonBookBlurb, PromoteSnippet @@ -72,6 +72,10 @@ def setUp(self): amazon_book_blurb="Amazon Book Blurb. Amazon Book Blurb. Amazon Book Blurb.") self.amazon_book_blurb.save() + self.content_warning_message = ContentWarningMessage( + content_warning_message = "Content Warning Message") + self.content_warning_message.save() + def test_can_create_subject(self): 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): promote_snippet.save() self.assertEqual(promote_snippet.name, "Assignable") -