Skip to content

Commit

Permalink
Merge pull request #955 from GT-Codeur/constant-streamfield
Browse files Browse the repository at this point in the history
Constant streamfield
  • Loading branch information
brylie authored Nov 22, 2023
2 parents 375b144 + f6bec1e commit 99accb7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 125 deletions.
13 changes: 13 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version = 1

[[analyzers]]
name = "shell"

[[analyzers]]
name = "javascript"

[[analyzers]]
name = "python"

[analyzers.meta]
runtime_version = "3.x.x"
36 changes: 36 additions & 0 deletions core/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from wagtail import blocks as wagtail_blocks
from blocks.blocks import (
FormattedImageChooserStructBlock,
HeadingBlock,
PreformattedTextBlock,
PullQuoteBlock,
SpacerBlock,
)
from documents.blocks import DocumentEmbedBlock

STREAMFIELD_SETTINGS = [
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"superscript",
"superscript",
"strikethrough",
"blockquote",
],
),
),
("pullquote", PullQuoteBlock()),
("document", DocumentEmbedBlock()),
("image", FormattedImageChooserStructBlock(classname="full title")),
("spacer", SpacerBlock()),
("preformatted_text", PreformattedTextBlock()),
]
10 changes: 2 additions & 8 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
from django.http import Http404, HttpRequest
from modelcluster.fields import ParentalKey # type: ignore
from timezone_field import TimeZoneField # type: ignore
from wagtail import blocks as wagtail_blocks
from wagtail.admin.panels import FieldPanel, InlinePanel, PageChooserPanel
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Orderable, Page
from wagtail.search import index

from blocks.blocks import FormattedImageChooserStructBlock, HeadingBlock, SpacerBlock
from common.models import DrupalFields
from core.constants import STREAMFIELD_SETTINGS
from pagination.helpers import get_paginated_items


Expand Down Expand Up @@ -42,12 +41,7 @@ class EventCategoryChoices(models.TextChoices):

teaser = models.TextField(max_length=100, null=True, blank=True)
body = StreamField(
[
("heading", HeadingBlock()),
("rich_text", wagtail_blocks.RichTextBlock()),
("image", FormattedImageChooserStructBlock()),
("spacer", SpacerBlock()),
],
STREAMFIELD_SETTINGS,
null=True,
blank=True,
use_json_field=True,
Expand Down
49 changes: 2 additions & 47 deletions library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@
from modelcluster.contrib.taggit import ClusterTaggableManager # type: ignore
from modelcluster.fields import ParentalKey # type: ignore
from taggit.models import TaggedItemBase # type: ignore
from wagtail import blocks as wagtail_blocks
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
PageChooserPanel,
)
from wagtail.embeds.blocks import EmbedBlock
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Orderable, Page
from wagtail.search import index

from blocks.blocks import (
FormattedImageChooserStructBlock,
HeadingBlock,
MediaBlock,
PreformattedTextBlock,
PullQuoteBlock,
SpacerBlock,
WfURLBlock,
)
from common.models import DrupalFields
from documents.blocks import DocumentEmbedBlock
from core.constants import STREAMFIELD_SETTINGS
from facets.models import Audience, Genre, Medium, TimePeriod, Topic
from library.helpers import create_querystring_from_facets, filter_querystring_facets
from pagination.helpers import get_paginated_items
Expand All @@ -47,41 +36,7 @@ class LibraryItem(DrupalFields, Page): # type: ignore
help_text="This field indicates when a library item wasn't published on a specific publication date.", # noqa: E501
)
body = StreamField(
[
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"hr",
"blockquote",
],
),
),
(
"image",
FormattedImageChooserStructBlock(
classname="full title",
),
),
("document", DocumentEmbedBlock()),
(
"media",
MediaBlock(
icon="media",
),
),
("embed", EmbedBlock()),
("url", WfURLBlock()),
("pullquote", PullQuoteBlock()),
("spacer", SpacerBlock()),
("preformatted_text", PreformattedTextBlock()),
],
STREAMFIELD_SETTINGS,
null=True,
blank=True,
use_json_field=True,
Expand Down
37 changes: 2 additions & 35 deletions magazine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from modelcluster.fields import ParentalKey # type: ignore
from modelcluster.models import ClusterableModel # type: ignore
from taggit.models import TaggedItemBase # type: ignore
from wagtail import blocks as wagtail_blocks
from wagtail.admin.panels import (
FieldPanel,
FieldRowPanel,
Expand All @@ -22,15 +21,8 @@
from wagtail.models import Orderable, Page
from wagtail.search import index

from blocks.blocks import (
FormattedImageChooserStructBlock,
HeadingBlock,
PreformattedTextBlock,
PullQuoteBlock,
SpacerBlock,
)
from common.models import DrupalFields
from documents.blocks import DocumentEmbedBlock
from core.constants import STREAMFIELD_SETTINGS
from pagination.helpers import get_paginated_items

from .panels import NestedInlinePanel
Expand Down Expand Up @@ -273,32 +265,7 @@ class MagazineArticle(DrupalFields, Page): # type: ignore
],
)
body = StreamField(
[
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"superscript",
"superscript",
"strikethrough",
"blockquote",
],
),
),
("pullquote", PullQuoteBlock()),
("document", DocumentEmbedBlock()),
("image", FormattedImageChooserStructBlock(classname="full title")),
("spacer", SpacerBlock()),
("preformatted_text", PreformattedTextBlock()),
],
STREAMFIELD_SETTINGS,
use_json_field=True,
)
is_featured = models.BooleanField(
Expand Down
37 changes: 2 additions & 35 deletions news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase
from wagtail import blocks as wagtail_blocks
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.embeds.blocks import EmbedBlock
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page
from wagtail.search import index

from blocks.blocks import (
FormattedImageChooserStructBlock,
HeadingBlock,
PullQuoteBlock,
SpacerBlock,
)
from common.models import DrupalFields
from documents.blocks import DocumentEmbedBlock
from core.constants import STREAMFIELD_SETTINGS


class NewsIndexPage(Page):
Expand Down Expand Up @@ -150,32 +142,7 @@ class NewsItem(DrupalFields, Page):
)
publication_date = models.DateField(default=date.today)
body = StreamField(
[
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"superscript",
"superscript",
"strikethrough",
"blockquote",
],
),
),
("pullquote", PullQuoteBlock()),
("image", FormattedImageChooserStructBlock(classname="full title")),
("document", DocumentEmbedBlock()),
("spacer", SpacerBlock()),
("embed", EmbedBlock()),
],
STREAMFIELD_SETTINGS,
use_json_field=True,
)
tags = ClusterTaggableManager(
Expand Down

0 comments on commit 99accb7

Please sign in to comment.