Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Global Constant STREAMFIELD_SETTINGS for site-wide rich text edit… #953

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions core/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from blocks.blocks import (
FormattedImageChooserStructBlock,
HeadingBlock,
PullQuoteBlock,
SpacerBlock,
)
from wagtail import blocks as wagtail_blocks
from documents.blocks import DocumentEmbedBlock

# StreamField Settings
STREAMFIELD_SETTINGS = [
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"superscript",
"superscript",
"strikethrough",
],
),
),
("pullquote", PullQuoteBlock()),
("document", DocumentEmbedBlock()),
("image", FormattedImageChooserStructBlock(classname="full title")),
("spacer", SpacerBlock()),
]
10 changes: 2 additions & 8 deletions events/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from core.constants import STREAMFIELD_SETTINGS
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.utils import timezone
from django.db import models
from django.db.models import Q
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


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
47 changes: 2 additions & 45 deletions library/models.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
from core.constants import STREAMFIELD_SETTINGS
from django.db import models
from django.http import HttpRequest
from django_flatpickr.widgets import DatePickerInput
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,
PullQuoteBlock,
SpacerBlock,
WfURLBlock,
)
from common.models import DrupalFields
from documents.blocks import DocumentEmbedBlock
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 @@ -46,39 +35,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",
],
),
),
(
"image",
FormattedImageChooserStructBlock(
classname="full title",
),
),
("document", DocumentEmbedBlock()),
(
"media",
MediaBlock(
icon="media",
),
),
("embed", EmbedBlock()),
("url", WfURLBlock()),
("pullquote", PullQuoteBlock()),
("spacer", SpacerBlock()),
],
STREAMFIELD_SETTINGS,
null=True,
blank=True,
use_json_field=True,
Expand Down
35 changes: 2 additions & 33 deletions magazine/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from datetime import timedelta

from core.constants import STREAMFIELD_SETTINGS
from django.core.paginator import Paginator
from django.db import models
from django.db.models import QuerySet
Expand All @@ -10,7 +11,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 +22,7 @@
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Orderable, 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 pagination.helpers import get_paginated_items

from .panels import NestedInlinePanel
Expand Down Expand Up @@ -284,30 +276,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",
],
),
),
("pullquote", PullQuoteBlock()),
("document", DocumentEmbedBlock()),
("image", FormattedImageChooserStructBlock(classname="full title")),
("spacer", SpacerBlock()),
],
STREAMFIELD_SETTINGS,
use_json_field=True,
)
is_featured = models.BooleanField(
Expand Down
38 changes: 2 additions & 36 deletions news/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
from datetime import date, datetime

from core.constants import STREAMFIELD_SETTINGS
from django.db import models
from django.http import HttpRequest
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


class NewsIndexPage(Page):
Expand Down Expand Up @@ -150,32 +141,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