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

Added Amazon Book Blurb snippet #1520

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
29 changes: 29 additions & 0 deletions snippets/migrations/0030_amazonbookblurb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.1.7 on 2023-10-26 18:41

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0077_alter_revision_user'),
('snippets', '0029_assignableavailable'),
]

operations = [
migrations.CreateModel(
name='AmazonBookBlurb',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('translation_key', models.UUIDField(default=uuid.uuid4, editable=False)),
('amazon_book_blurb', 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')},
},
),
]
16 changes: 16 additions & 0 deletions snippets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,19 @@ def __str__(self):


register_snippet(AssignableAvailable)


class AmazonBookBlurb(TranslatableMixin, models.Model):
amazon_book_blurb = models.TextField()

api_fields = ('amazon_book_blurb')

panels = [
FieldPanel('amazon_book_blurb')
]

def __str__(self):
return 'Amazon Book Blurb'


register_snippet(AmazonBookBlurb)
9 changes: 8 additions & 1 deletion 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, AssignableAvailable
BlogCollection, NoWebinarMessage, WebinarCollection, AssignableAvailable, AmazonBookBlurb

from rest_framework import serializers, generics

Expand Down Expand Up @@ -134,3 +134,10 @@ class Meta:
read_only_fields = ('assignable_description',
'assignable_available_image')


class AmazonBookBlurbSerializer(serializers.ModelSerializer):
class Meta:
model = AmazonBookBlurb
fields = ('amazon_book_blurb',)
read_only_fields = ('amazon_book_blurb',)

7 changes: 6 additions & 1 deletion snippets/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from global_settings.functions import invalidate_cloudfront_caches
from snippets.models import Subject, Role, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, \
WebinarCollection, AssignableAvailable
WebinarCollection, AssignableAvailable, AmazonBookBlurb


@receiver(post_save, sender=Subject)
Expand Down Expand Up @@ -49,3 +49,8 @@ def clear_cloudfront_on_webinar_collection_save(sender, **kwargs):
@receiver(post_save, sender=AssignableAvailable)
def clear_cloudfront_on_assignable_available_save(sender, **kwargs):
invalidate_cloudfront_caches('snippets/assignableavailable')


@receiver(post_save, sender=AmazonBookBlurb)
def clear_cloudfront_on_amazon_book_blurb_save(sender, **kwargs):
invalidate_cloudfront_caches('snippets/amazonbookblurb')
11 changes: 10 additions & 1 deletion snippets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from django.urls import reverse

from snippets.models import Subject, ErrataContent, GiveBanner, BlogContentType, NoWebinarMessage, K12Subject, \
FacultyResource, StudentResource, Role, SharedContent, NewsSource, SubjectCategory, BlogCollection, AssignableAvailable
FacultyResource, StudentResource, Role, SharedContent, NewsSource, SubjectCategory, BlogCollection, \
AssignableAvailable, AmazonBookBlurb
import snippets


Expand Down Expand Up @@ -70,6 +71,10 @@ def setUp(self):
assignable_description="Assignable is ...")
self.assignable_available.save()

self.amazon_book_blurb = AmazonBookBlurb(
amazon_book_blurb="Amazon Book Blurb. Amazon Book Blurb. Amazon Book Blurb.")
self.amazon_book_blurb.save()

def test_can_create_subject(self):
subject = Subject(name="Science", page_content="Science page content.", seo_title="Science SEO Title",
search_description="Science page description.")
Expand Down Expand Up @@ -143,3 +148,7 @@ def test_can_fetch_assignable_available(self):
response = self.client.get('/apps/cms/api/snippets/assignableavailable/?format=json')
self.assertIn(b"Assignable is ...", response.content)

def test_can_fetch_amazon_book_blurb(self):
response = self.client.get('/apps/cms/api/snippets/amazonbookblurb/?format=json')
self.assertIn(b"Amazon Book Blurb", response.content)

1 change: 1 addition & 0 deletions snippets/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
router.register('nowebinarmessage', views.NoWebinarMessageViewSet, basename="NoWebinarMessage")
router.register('webinarcollection', views.WebinarCollectionViewSet, basename="WebinarCollection")
router.register('assignableavailable', views.AssignableAvailableViewSet, basename="AssignableAvailable")
router.register('amazonbookblurb', views.AmazonBookBlurbViewSet, basename="AmazonBookBlurb")
urlpatterns = router.urls
9 changes: 7 additions & 2 deletions snippets/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from rest_framework import viewsets

from .models import Role, Subject, K12Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, \
BlogCollection, NoWebinarMessage, WebinarCollection, AssignableAvailable
BlogCollection, NoWebinarMessage, WebinarCollection, AssignableAvailable, AmazonBookBlurb
from .serializers import RoleSerializer, SubjectSerializer, K12SubjectSerializer, ErrataContentSerializer, \
SubjectCategorySerializer, \
GiveBannerSerializer, BlogContentTypeSerializer, BlogCollectionSerializer, NoWebinarMessageSerializer, \
WebinarCollectionSerializer, AssignableAvailableSerializer
WebinarCollectionSerializer, AssignableAvailableSerializer, AmazonBookBlurbSerializer

from rest_framework import generics, viewsets
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -109,6 +109,11 @@ class AssignableAvailableViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = AssignableAvailableSerializer


class AmazonBookBlurbViewSet(viewsets.ReadOnlyModelViewSet):
queryset = AmazonBookBlurb.objects.all()
serializer_class = AmazonBookBlurbSerializer


def convert_locale(locale):
if locale == 'es':
return SPANISH_LOCALE_ID
Expand Down