Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ContentWarningMessage #1563

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions snippets/migrations/0036_contentwarningmessage.py
Original file line number Diff line number Diff line change
@@ -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")},
},
),
]
14 changes: 14 additions & 0 deletions snippets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,17 @@


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'

Check warning on line 499 in snippets/models.py

View check run for this annotation

Codecov / codecov/patch

snippets/models.py#L499

Added line #L499 was not covered by tests

register_snippet(ContentWarningMessage)
18 changes: 11 additions & 7 deletions snippets/serializers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',)
5 changes: 4 additions & 1 deletion snippets/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')
7 changes: 5 additions & 2 deletions snippets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -151,4 +155,3 @@ def test_can_create_promote_snippet(self):
promote_snippet.save()

self.assertEqual(promote_snippet.name, "Assignable")

Loading