Skip to content

Commit

Permalink
Add shared Errata page template (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo authored and RoyEJohnson committed Nov 9, 2017
1 parent 19cb9ba commit 6a10b29
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
29 changes: 29 additions & 0 deletions pages/migrations/0102_erratalist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-09 15:43
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import wagtail.wagtailcore.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0040_page_draft_title'),
('pages', '0101_auto_20170928_1413'),
]

operations = [
migrations.CreateModel(
name='ErrataList',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('correction_schedule', wagtail.wagtailcore.fields.RichTextField()),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
16 changes: 16 additions & 0 deletions pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class Meta:
'pages.InterestForm',
'pages.Marketing',
'pages.Technology',
'pages.ErrataList',
'books.BookIndex',
'news.NewsIndex',
'allies.Ally',
Expand Down Expand Up @@ -1343,3 +1344,18 @@ class Technology(Page):
]

parent_page_types = ['pages.HomePage']


class ErrataList(Page):
correction_schedule = RichTextField(features=['link', 'bold', 'italic', 'hr', 'ol', 'ul'])

api_fields = (
'correction_schedule',
)

content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('correction_schedule')
]

parent_page_types = ['pages.HomePage']
9 changes: 8 additions & 1 deletion pages/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
AdoptForm,
InterestForm,
Marketing,
Technology)
Technology,
ErrataList)

from rest_framework import serializers

Expand Down Expand Up @@ -151,3 +152,9 @@ class TechnologySerializer(PageSerializer):
class Meta:
model = Technology
fields = Technology.api_fields


class ErrataListSerializer(PageSerializer):
class Meta:
model = ErrataList
fields = ErrataList.api_fields
23 changes: 20 additions & 3 deletions pages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
AdoptForm,
InterestForm,
Marketing,
Technology)
Technology,
ErrataList)
from allies.models import Ally
from news.models import NewsIndex
from books.models import BookIndex
Expand Down Expand Up @@ -70,10 +71,27 @@ def test_allowed_subpages(self):
AdoptForm,
InterestForm,
Marketing,
Technology
Technology,
ErrataList
})


class ErrataListTest(WagtailPageTests):

def test_can_create_errata_list_page(self):
root_page = Page.objects.get(title="Root")
homepage = HomePage(title="Hello World",
slug="hello-world",
)
root_page.add_child(instance=homepage)
errata_list_page = ErrataList(title="Errata List Template",
correction_schedule="Some sample correction schedule text.")
homepage.add_child(instance=errata_list_page)

retrieved_page = Page.objects.get(id=errata_list_page.id)
self.assertEqual(retrieved_page.title, "Errata List Template")


class AdminPages(TestCase, WagtailTestUtils):

def setUp(self):
Expand Down Expand Up @@ -116,4 +134,3 @@ def test_admin_search(self):
response = self.client.get('/admin/pages/search/?q=openstax')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Sorry, no pages match', response.content)

17 changes: 11 additions & 6 deletions pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
AdoptForm,
InterestForm,
Marketing,
Technology)
Technology,
ErrataList)
from .serializers import (HomePageSerializer,
HigherEducationSerializer,
GeneralPageSerializer,
Expand All @@ -42,7 +43,8 @@
AdoptFormSerializer,
InterestFormSerializer,
MarketingSerializer,
TechnologySerializer)
TechnologySerializer,
ErrataListSerializer)


class JSONResponse(HttpResponse):
Expand All @@ -64,10 +66,6 @@ def page_detail(request, slug):

try:
page = HomePage.objects.get(slug=slug)
for column in page.row_1:
for name, block in column.value.bound_blocks.items():
if name == 'image':
print(block.value)
serializer = HomePageSerializer(page)
return JSONResponse(serializer.data)
except HomePage.DoesNotExist:
Expand Down Expand Up @@ -213,5 +211,12 @@ def page_detail(request, slug):
except Technology.DoesNotExist:
page_found = False

try:
page = ErrataList.objects.get(slug=slug)
serializer = ErrataListSerializer(page)
return JSONResponse(serializer.data)
except ErrataList.DoesNotExist:
page_found = False

if not page_found:
return HttpResponse(status=404)

0 comments on commit 6a10b29

Please sign in to comment.