Skip to content

Commit

Permalink
🦶 Footnotes (#156)
Browse files Browse the repository at this point in the history
Adds footnotes to exhibits body
  • Loading branch information
mrharpo authored Feb 21, 2024
1 parent 0852c81 commit 664ac40
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 2 deletions.
38 changes: 38 additions & 0 deletions exhibits/migrations/0008_alter_exhibitpage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.10 on 2024-02-07 23:27

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


class Migration(migrations.Migration):

dependencies = [
("exhibits", "0007_alter_exhibitpage_body"),
]

operations = [
migrations.AlterField(
model_name="exhibitpage",
name="body",
field=wagtail.fields.StreamField(
[
("text", wagtail_footnotes.blocks.RichTextBlockWithFootnotes()),
(
"heading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
(
"subheading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
],
use_json_field=True,
),
),
]
56 changes: 56 additions & 0 deletions exhibits/migrations/0009_alter_exhibitpage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.10 on 2024-02-07 23:37

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


class Migration(migrations.Migration):

dependencies = [
("exhibits", "0008_alter_exhibitpage_body"),
]

operations = [
migrations.AlterField(
model_name="exhibitpage",
name="body",
field=wagtail.fields.StreamField(
[
(
"text",
wagtail_footnotes.blocks.RichTextBlockWithFootnotes(
features=[
"bold",
"italic",
"h2",
"h3",
"h4",
"ol",
"ul",
"hr",
"link",
"image",
"blockquote",
"footnotes",
]
),
),
(
"heading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
(
"subheading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
],
use_json_field=True,
),
),
]
38 changes: 38 additions & 0 deletions exhibits/migrations/0010_alter_exhibitpage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.10 on 2024-02-07 23:44

from django.db import migrations
import exhibits.models
import wagtail.blocks
import wagtail.fields


class Migration(migrations.Migration):

dependencies = [
("exhibits", "0009_alter_exhibitpage_body"),
]

operations = [
migrations.AlterField(
model_name="exhibitpage",
name="body",
field=wagtail.fields.StreamField(
[
("text", exhibits.models.RichTextFootnotesBlock()),
(
"heading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
(
"subheading",
wagtail.blocks.RichTextBlock(
features=["italic"], form_classname="title", icon="title"
),
),
],
use_json_field=True,
),
),
]
28 changes: 27 additions & 1 deletion exhibits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,33 @@
from wagtail.images.api.fields import ImageRenditionField
from wagtail.models import Orderable, Page
from wagtail.search import index
from wagtail_footnotes.blocks import RichTextBlockWithFootnotes
from wagtail_headless_preview.models import HeadlessMixin

from authors.serializers import AuthorSerializer
from ov_wag.serializers import FootnotesSerializer


class RichTextFootnotesBlock(RichTextBlockWithFootnotes):
def __init__(
self,
features=(
'bold',
'italic',
'h2',
'h3',
'h4',
'ol',
'ul',
'hr',
'link',
'image',
'blockquote',
'footnotes',
),
**kwargs,
):
super().__init__(features=features, **kwargs)


class ExhibitsOrderable(Orderable):
Expand Down Expand Up @@ -105,7 +129,7 @@ class ExhibitPageApiSchema(ExhibitsApiSchema):
class ExhibitPage(HeadlessMixin, Page):
body = StreamField(
[
('text', RichTextBlock()),
('text', RichTextFootnotesBlock()),
(
'heading',
RichTextBlock(
Expand Down Expand Up @@ -153,6 +177,7 @@ class ExhibitPage(HeadlessMixin, Page):
FieldPanel('body', classname='collapsed'),
InlinePanel('authors', heading='Author(s)'),
InlinePanel('other_exhibits', heading='Other Exhibits', max_num=3),
InlinePanel('footnotes', label='Footnotes'),
]

promote_panels: ClassVar[list[FieldPanel]] = [
Expand Down Expand Up @@ -184,6 +209,7 @@ class ExhibitPage(HeadlessMixin, Page):
serializer=ImageRenditionField('fill-480x270', source='hero_image'),
),
APIField('authors'),
APIField('footnotes', serializer=FootnotesSerializer()),
OtherExhibitsField(
'other_exhibits', serializer=OtherExhibitsSerializer(many=True)
),
Expand Down
14 changes: 14 additions & 0 deletions ov_wag/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
from pydantic import BaseModel
from rest_framework.fields import Field
from wagtail.templatetags import wagtailcore_tags


class FootnoteAPIModel(BaseModel):
id: int
uuid: str
text: str


class FootnotesSerializer(Field):
def to_representation(self, value):
return [
FootnoteAPIModel(**footnote).model_dump() for footnote in value.values()
]


class RichTextSerializer(Field):
def to_representation(self, value):
return wagtailcore_tags.richtext(value)
1 change: 1 addition & 0 deletions ov_wag/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'django.contrib.staticfiles',
'wagtail_headless_preview',
'wagtail.contrib.search_promotions',
"wagtail_footnotes",
'django.contrib.sites',
'allauth',
'allauth.account',
Expand Down
2 changes: 2 additions & 0 deletions ov_wag/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail_footnotes import urls as footnotes_urls

from search import views as search_views

Expand All @@ -16,6 +17,7 @@
path('search/', search_views.search, name='search'),
path('api/v2/', api_router.urls),
path('accounts/', include('allauth.urls')),
path("footnotes/", include(footnotes_urls)),
]


Expand Down
17 changes: 16 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies = [
"django-cors-headers~=4.3",
"django-allauth~=0.60",
"elasticsearch~=8.12",
"wagtail-footnotes>=0.10.0",
]
requires-python = '>=3.9,<4.0'

Expand Down

0 comments on commit 664ac40

Please sign in to comment.