Skip to content

Instantly share code, notes, and snippets.

@shacker
Last active November 26, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shacker/0dfee4742e0626a20015018817af4126 to your computer and use it in GitHub Desktop.
Save shacker/0dfee4742e0626a20015018817af4126 to your computer and use it in GitHub Desktop.
BlockQuoteBlock for use with Wagtail Streamfields
from django import forms
from django.utils.encoding import force_text
from django.utils.html import format_html
from wagtail.wagtailcore.blocks import FieldBlock
class BlockQuoteBlock(FieldBlock):
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs):
self.field = forms.CharField(
required=required,
help_text=help_text,
max_length=max_length,
min_length=min_length
)
super(BlockQuoteBlock, self).__init__(**kwargs)
def get_searchable_content(self, value):
return [force_text(value)]
def render_basic(self, value, context=None):
if value:
return format_html('<blockquote>{0}</blockquote>', value)
else:
return ''
class Meta:
icon = "openquote"
# Then in your models.py, e.g::
from cms.stream_blocks import BlockQuoteBlock
...
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
('blockquote', BlockQuoteBlock()),
], blank=True, null=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment