-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collection, subject and category are not required on blog posts, adde…
…d webinar search by subject (#1307) * Collection, subject and category are not required on blog posts, added webinar search by subject * removed unneeded code * Fixed Webinar API for search and all webinars * Fixed test * Added test for all webinars * Removed commented out code
- Loading branch information
1 parent
89af955
commit 30ef3bb
Showing
10 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 3.2.5 on 2022-06-16 18:49 | ||
|
||
from django.db import migrations | ||
import news.models | ||
import wagtail.core.blocks | ||
import wagtail.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('news', '0045_merge_20220520_1523'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='newsarticle', | ||
name='article_subjects', | ||
field=wagtail.core.fields.StreamField([('subject', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('subject', news.models.BlogCollectionChooserBlock(label='Blog Subject', required=True, target_model='snippets.Subject')), ('featured', wagtail.core.blocks.BooleanBlock(label='Featured', required=False))])))], blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='newsarticle', | ||
name='collections', | ||
field=wagtail.core.fields.StreamField([('collection', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('collection', news.models.BlogCollectionChooserBlock(label='Blog Collection', required=True, target_model='snippets.BlogCollection')), ('featured', wagtail.core.blocks.BooleanBlock(label='Featured', required=False)), ('popular', wagtail.core.blocks.BooleanBlock(label='Popular', required=False))])))], blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='newsarticle', | ||
name='content_types', | ||
field=wagtail.core.fields.StreamField([('content_type', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('content_type', news.models.ContentTypeChooserBlock(label='Blog Content Type', required=True, target_model='snippets.BlogContentType'))])))], blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 3.2.5 on 2022-06-16 18:58 | ||
|
||
from django.db import migrations | ||
import news.models | ||
import wagtail.core.blocks | ||
import wagtail.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('webinars', '0002_webinar_display_on_tutor_page'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='webinar', | ||
name='webinar_subjects', | ||
field=wagtail.core.fields.StreamField([('subject', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('subject', news.models.BlogCollectionChooserBlock(label='Blog Subject', required=True, target_model='snippets.Subject')), ('featured', wagtail.core.blocks.BooleanBlock(label='Featured', required=False))])))], blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
from rest_framework import serializers | ||
from .models import Webinar | ||
|
||
|
||
class WebinarSerializer(serializers.ModelSerializer): | ||
def __init__(self, *args, **kwargs): | ||
super(WebinarSerializer, self).__init__(*args, **kwargs) | ||
subjects = serializers.SerializerMethodField() | ||
|
||
for field in self.fields: | ||
self.fields[field].read_only = True | ||
def get_subjects(self, obj): | ||
return obj.selected_subjects_json() | ||
|
||
class Meta: | ||
model = Webinar | ||
fields = '__all__' | ||
fields = ('id', | ||
'start', | ||
'end', | ||
'description', | ||
'speakers', | ||
'spaces_remaining', | ||
'registration_url', | ||
'registration_link_text', | ||
'display_on_tutor_page', | ||
'subjects') | ||
read_only_fields = ('id', | ||
'start', | ||
'end', | ||
'description', | ||
'speakers', | ||
'spaces_remaining', | ||
'registration_url', | ||
'registration_link_text', | ||
'display_on_tutor_page', | ||
'subjects') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import json | ||
|
||
from django.test import TestCase | ||
from django.utils import timezone | ||
from wagtail.tests.utils import WagtailPageTests | ||
|
||
from snippets.models import Subject | ||
from webinars.models import Webinar | ||
|
||
|
||
class WebinarTests(WagtailPageTests, TestCase): | ||
def setUp(self): | ||
# create subjects | ||
self.math = Subject(name="Math", page_content="Math page content.", seo_title="Math SEO Title", | ||
search_description="Math page description.") | ||
self.math.save() | ||
math_id = self.math.id | ||
|
||
self.economics = Subject(name="Economics", page_content="Economics page content.", | ||
seo_title="Economics SEO Title", | ||
search_description="Economics page description.") | ||
self.economics.save() | ||
economics_id = self.economics.id | ||
|
||
# create webinars | ||
self.webinar = Webinar(title="Webinar 1", | ||
start=timezone.now(), | ||
end=timezone.now(), | ||
description='Webinar 1 description', | ||
speakers='Bob, Mary. Sally, Mike', | ||
spaces_remaining=45, | ||
registration_url='https://example.com', | ||
registration_link_text='Register Now', | ||
display_on_tutor_page=False, | ||
webinar_subjects=json.dumps( | ||
[ | ||
|
||
{"type": "subject", "value": [ | ||
{"type": "item", "value": {"subject": math_id, "featured": False}, | ||
"id": "fb443e9a-5487-4b5e-86f3-69017c0327b5"}] | ||
} | ||
] | ||
), | ||
) | ||
self.webinar.save() | ||
self.webinar2 = Webinar(title="Webinar 2", | ||
start=timezone.now(), | ||
end=timezone.now(), | ||
description='Webinar 2 description', | ||
speakers='Stan, Steve, Tony', | ||
spaces_remaining=54, | ||
registration_url='https://example.com', | ||
registration_link_text='Register Now', | ||
display_on_tutor_page=False, | ||
webinar_subjects=json.dumps( | ||
[ | ||
|
||
{"type": "subject", "value": [ | ||
{"type": "item", "value": {"subject": economics_id, "featured": False}, | ||
"id": "fb443e9a-5487-4b5e-86f3-69017c0327b5"}] | ||
} | ||
] | ||
), | ||
) | ||
self.webinar2.save() | ||
|
||
def test_search_subject_only(self): | ||
response = self.client.get('/apps/cms/api/webinars/?subject=Math') | ||
self.assertContains(response, 'Math') | ||
|
||
def test_all_webinars(self): | ||
response = self.client.get('/apps/cms/api/webinars/') | ||
self.assertContains(response, 'Math') | ||
self.assertContains(response, 'Economics') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
from rest_framework import viewsets | ||
|
||
from django.shortcuts import render | ||
from django.http import JsonResponse | ||
from django.conf import settings | ||
|
||
from .models import Webinar | ||
from .models import Webinar, webinar_subject_search | ||
from .serializers import WebinarSerializer | ||
|
||
|
||
class WebinarViewSet(viewsets.ModelViewSet): | ||
queryset = Webinar.objects.all() | ||
serializer_class = WebinarSerializer | ||
|
||
def get_queryset(self): | ||
queryset = Webinar.objects.all() | ||
subject = self.request.query_params.get('subject', None) | ||
if subject is not None: | ||
queryset = webinar_subject_search(subject) | ||
return queryset |