Last active
November 26, 2016 19:07
-
-
Save shacker/0dfee4742e0626a20015018817af4126 to your computer and use it in GitHub Desktop.
BlockQuoteBlock for use with Wagtail Streamfields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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