Skip to content

Commit

Permalink
💿 AAPB records (#138)
Browse files Browse the repository at this point in the history
Adds RawHTML block type for Collection content

The RawHTML block type allows embedding AAPB media using AAPB's embed
snippets from the AAPB website into OV collections.

Also,
* Adds a custom content block that stores a list of AAPB record IDs
  and configuration values that can affect the front end display
  of AAPB records.
* Returns the AAPB records data in API requests.

Closes #128
Closes #103
Closes #134
  • Loading branch information
afred authored Dec 13, 2023
1 parent 63099b6 commit 8484c60
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 9 deletions.
50 changes: 45 additions & 5 deletions ov_collections/blocks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from wagtail.blocks import RichTextBlock, StructBlock, URLBlock
from wagtail.blocks import (
BooleanBlock,
RichTextBlock,
StructBlock,
TextBlock,
URLBlock,
)
from wagtail.images.blocks import ImageChooserBlock


class ContentBlock(StructBlock):
"""Generic content block
- title
- link
All fields are required
This is the base block for all content blocks. All fields are required
Attributes:
title: RichTextBlock with italics only
link: URLBlock
"""

title = RichTextBlock(
Expand All @@ -21,7 +30,9 @@ class ContentBlock(StructBlock):

class ContentImageBlock(ContentBlock):
"""Generic content block with image
- image: required
Attributes:
image: ImageChooserBlock. Required.
"""

image = ImageChooserBlock(required=True)
Expand All @@ -30,3 +41,32 @@ def get_api_representation(self, value, context=None):
results = super().get_api_representation(value, context)
results['image'] = value.get('image').get_rendition('width-400').attrs_dict
return results


class AAPBRecordsBlock(StructBlock):
"""AAPB Records block
A list of AAPB records to be displayed as a group. The records can be displayed in
different ways, depending on the options selected.
Attributes:
ids: required. List of GUIDs, separated by whitespace
show_title: optional
show_thumbnail: optional
show_description: optional
"""

ids = TextBlock(
required=True,
help_text='AAPB record IDs, separated by whitespace',
)

show_title = BooleanBlock(required=False, help_text='Show title', default=True)

show_thumbnail = BooleanBlock(
required=False, help_text='Show thumbnail', default=True
)

show_description = BooleanBlock(
required=False, help_text='Show description', default=False
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.7 on 2023-12-05 20:37

from django.db import migrations
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('ov_collections', '0009_collection_hero_image'),
]

operations = [
migrations.AddField(
model_name='collection',
name='aapb_records',
field=wagtail.fields.StreamField([('ids', wagtail.blocks.TextBlock())], default='', use_json_field=True),
),
migrations.AlterField(
model_name='collection',
name='content',
field=wagtail.fields.StreamField([('interviews', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))], icon='openquote', label='Interview'), icon='openquote')), ('archival_footage', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))], icon='form', label='Footage'), icon='form')), ('photographs', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))], icon='image', label='Photograph'), icon='image')), ('original_footage', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(required=True))], icon='doc-full-inverse', label='Footage'), icon='doc-full-inverse')), ('programs', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True))], icon='clipboard-list', label='Program'), icon='clipboard-list')), ('related_content', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock(help_text='The title of this content', max_length=1024, required=True)), ('link', wagtail.blocks.URLBlock(required=True))], icon='list-ul', label='Content'), icon='list-ul')), ('credits', wagtail.blocks.RichTextBlock()), ('heading', wagtail.blocks.CharBlock(form_classname='title')), ('text', wagtail.blocks.TextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('html', wagtail.blocks.RawHTMLBlock())], use_json_field=True),
),
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-11-29 20:21
# Generated by Django 4.2.7 on 2023-12-07 18:11

from django.db import migrations
import wagtail.blocks
Expand All @@ -8,10 +8,58 @@

class Migration(migrations.Migration):
dependencies = [
("ov_collections", "0009_collection_hero_image"),
("ov_collections", "0010_collection_aapb_records_alter_collection_content"),
]

operations = [
migrations.AlterField(
model_name="collection",
name="aapb_records",
field=wagtail.fields.StreamField(
[
(
"aapb_record_group",
wagtail.blocks.StructBlock(
[
(
"ids",
wagtail.blocks.TextBlock(
help_text="AAPB record IDs, separated by whitespace",
required=True,
),
),
(
"show_title",
wagtail.blocks.BooleanBlock(
default=True,
help_text="Show title",
required=False,
),
),
(
"show_thumbnail",
wagtail.blocks.BooleanBlock(
default=True,
help_text="Show thumbnail",
required=False,
),
),
(
"show_description",
wagtail.blocks.BooleanBlock(
default=False,
help_text="Show description",
required=False,
),
),
]
),
)
],
default="",
use_json_field=True,
),
),
migrations.AlterField(
model_name="collection",
name="content",
Expand Down Expand Up @@ -177,6 +225,7 @@ class Migration(migrations.Migration):
("heading", wagtail.blocks.CharBlock(form_classname="title")),
("text", wagtail.blocks.TextBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
("html", wagtail.blocks.RawHTMLBlock()),
],
use_json_field=True,
),
Expand Down
21 changes: 19 additions & 2 deletions ov_collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
from django.db import models
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.api import APIField
from wagtail.blocks import CharBlock, ListBlock, RichTextBlock, TextBlock
from wagtail.blocks import (
CharBlock,
ListBlock,
RichTextBlock,
TextBlock,
RawHTMLBlock,
)
from wagtail.fields import RichTextField, StreamField
from wagtail.images.api.fields import ImageRenditionField
from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Page
from wagtail.search import index
from wagtail_headless_preview.models import HeadlessMixin

from .blocks import ContentBlock, ContentImageBlock
from .blocks import ContentBlock, ContentImageBlock, AAPBRecordsBlock


class Collection(HeadlessMixin, Page):
Expand Down Expand Up @@ -60,6 +66,7 @@ class Collection(HeadlessMixin, Page):
('heading', CharBlock(form_classname='title')),
('text', TextBlock()),
('image', ImageChooserBlock()),
('html', RawHTMLBlock()),
],
use_json_field=True,
)
Expand All @@ -80,6 +87,14 @@ class Collection(HeadlessMixin, Page):
related_name='+',
)

aapb_records = StreamField(
[
('aapb_record_group', AAPBRecordsBlock()),
],
default='',
use_json_field=True,
)

search_fields: ClassVar[list[index.SearchField]] = [
*Page.search_fields,
index.SearchField('introduction'),
Expand All @@ -92,6 +107,7 @@ class Collection(HeadlessMixin, Page):
[FieldPanel('cover_image'), FieldPanel('hero_image')], heading='Images'
),
FieldPanel('content'),
FieldPanel('aapb_records'),
]

api_fields: ClassVar[list[APIField]] = [
Expand All @@ -110,4 +126,5 @@ class Collection(HeadlessMixin, Page):
serializer=ImageRenditionField('fill-480x270', source='hero_image'),
),
APIField('content'),
APIField('aapb_records'),
]

0 comments on commit 8484c60

Please sign in to comment.