class PaperBlock(StructBlock): picture = ImageChooserBlock(required=False) author = CharBlock() title = CharBlock() journal = CharBlock() link = URLBlock() class Meta: icon = 'fa fa-file-text' template = 'widgets/page-teaser.html' def get_context(self, value, parent_context=None): context = super(PaperBlock, self).get_context(value, parent_context=parent_context) c_update = { 'author': value.get('author'), 'title': value.get('title'), 'description': value.get('journal'), 'href': value.get('link'), 'external_link': True, 'external_link_text': 'Link', 'magicgrow': True, 'border': True, } context.update(c_update) image = value.get('picture') if image: rendition = image.get_rendition('fill-640x360-c100') context['image'] = {'url': rendition.url, 'name': image.title} # context['source'] = {'description': 'Link to paper', 'href': value.get('link')} return context
class _WhyChoseUsBlock(StructBlock): icon = _IconChoiceBlock() title = CharBlock(label='Название пункта', max_length=19) text = CharBlock( label='Текст под названием', max_length=80, )
class PullQuoteBlock(StructBlock): quote = CharBlock(classname="quote title") attribution = CharBlock(required=False) class Meta: icon = "openquote" template = 'longform/blocks/pull_quote.html'
def test_renditionawarestreamblock(self): """ Tests streamfield_tools.blocks.RenditionAwareStreamBlock """ test_stream_block = RenditionAwareStreamBlock([('bar', CharBlock()), ('baz', CharBlock())]) test_rendition = Rendition( short_name='foo', verbose_name="Foo", description="Foo Rendition", path_to_template='rendition_aware_struct_block/foo.html') test_stream_block.rendition = test_rendition html = test_stream_block.render( test_stream_block.to_python([ { 'type': 'bar', 'value': 'Bar' }, { 'type': 'baz', 'value': 'Baz' }, ])) self.assertHTMLEqual( html, """ <div class="block-bar">Bar</div> <div class="block-baz">Baz</div>""")
class LinkBlock(StructBlock): uri = CharBlock(required=True) text = CharBlock(required=False) icon = CharBlock(required=False) class Meta: icon = 'link'
class DefinitionListBlock(ContentBlock): definitions = ListBlock( StructBlock([('title', CharBlock()), ('definition', CharBlock())])) class Meta: icon = 'tag' template = 'blocks/definition_list.html'
class AboutPageStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image", icon="image")
class GlobalStreamBlock(StreamBlock): paragraph = RichTextBlock(icon="pilcrow", template="blocks/paragraph.html") header = StructBlock([ ('header_text', CharBlock(blank=True, required=False, label='Header')), ('size', ChoiceBlock(choices=[('', 'Select a header size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], blank=True, required=False)) ], classname="title", icon="title", template="blocks/header.html") image = StructBlock([('image', ImageChooserBlock()), ('caption', CharBlock(blank=True, required=False)), ('style', ChoiceBlock(choices=[('', 'Select an image size'), ('full', 'Full-width'), ('contain', 'Contained-width'), ('half', 'Half-width')], required=False))], icon="image", template="blocks/image.html") blockquote = StructBlock([ ('text', TextBlock()), ('attribute_name', CharBlock(blank=True, required=False, label='e.g. Guy Picciotto')), ('attribute_group', CharBlock(blank=True, required=False, label='e.g. Fugazi')), ], icon="openquote", template="blocks/blockquote.html") embed = EmbedBlock( help_text= 'Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks')
class QuoteBlock(StructBlock): quotation = CharBlock() author = CharBlock(required=False) title = CharBlock(required=False) class Meta: icon = 'openquote'
class CMSStreamBlock(StreamBlock): banner = BannerBlock(label='Banner section') ordered_list = OrderedListBlock( label='Ordered list section', help_text='Use this for sections similar to process') unordered_list = UnorderedListBlock( label='Unordered list block section', help_text='Use this for sections similar to services') image_list = ImageListBlock(label='Image list section') image_grid = ImageGridBlock(label='Image grid section', icon='table') featured_pages = FeaturedPageBlock(label='Featured pages section', icon='doc-full') live_feeds = LiveFeedsBlock(label='Live feeds section (blog/twitter)', icon='wagtail') h2 = CharBlock(icon='title', classname='title') h3 = CharBlock(icon='title', classname='title') h4 = CharBlock(icon='title', classname='title') h5 = CharBlock(icon='title', classname='title') intro = RichTextBlock(icon='pilcrow') paragraph = RichTextBlock(icon='pilcrow') pullquote = PullQuoteBlock(icon='openquote') image = ImageBlock(label='Aligned image', icon='image') document = DocumentChooserBlock(icon='doc-full-inverse') link = LinkBlock(icon='link') embed = EmbedBlock(icon='media') html = AlignedHTMLBlock(icon='code', label='Raw HTML')
class ImageBlock(StructBlock): image = ImageChooserBlock(required=True) caaption = CharBlock(required=False) attribute = CharBlock(required=False) class Meta: icon = 'image' template = 'blog/blocks/image_block.html'
class PullQuoteBlock(StructBlock): quote = TextBlock('quote title') attribution = CharBlock() affiliation = CharBlock(required=False) style = PullQuoteStyleChoiceBlock() class Meta: template = 'cms/blocks/pull_quote_block.html'
class ImageBlock(StructBlock): image = ImageChooserBlock() alignment = ImageFormatChoiceBlock() caption = CharBlock() attribution = CharBlock(required=False) class Meta: icon = "image"
class CounterPanel(StructBlock): title = CharBlock() subtitle = CharBlock() counters = ListBlock(CounterBlock) class Meta: icon = "title" template = "blocks/counter_panel.html"
class HomePageStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image", icon="image") pullquote = PullQuoteBlock() link = LinkBlock()
class ProductStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = TextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image", icon="image") embed = EmbedBlock() document = DocumentChooserBlock(icon="doc-full-inverse")
class TwitterBlock(StructBlock): twitter_box_username = CharBlock(required=True) twitter_box_widget_id = CharBlock(required=True) twitter_box_tweet_limit = IntegerBlock(required=True) class Meta: icon = "cog" label = "Twitter Widget" template = "ctdata/blocks/twitter.html"
class IconBlurbBlock(ContentBlock): icon = CharBlock(help_text='Text block passed as the icon selected. ' 'Choose between Ionic Icons or FontAwesome.') headline = CharBlock(required=False) body = RichTextBlock(required=False) class Meta: icon = 'image' template = 'blocks/icon_blurb.html'
class SkillbarBlock(ContentBlock): skills = ListBlock( StructBlock([('skill_percentage', CharBlock()), ('skill_name', CharBlock())])) class Meta: icon = 'form' template = 'blocks/skillbar.html'
class BlogStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") paragraph = RichTextBlock(icon="pilcrow") image = ImageChooserBlock() pullquote = PullQuoteBlock() document = DocumentChooserBlock(icon="doc-full-inverse") code = CodeBlock()
class BannerBlock(StructBlock): title = CharBlock() subtitle = CharBlock() image = ImageChooserBlock(required=False) image_copyright = CharBlock(required=False) style = BannerStyleChoiceBlock() class Meta: template = 'cms/blocks/banner_block.html'
class OrderedListBlock(StructBlock): title = CharBlock(required=False) items = ListBlock( StructBlock([('title', CharBlock()), ('description', TextBlock())])) label = CharBlock(required=False) page = PageChooserBlock(required=False) class Meta: template = 'cms/blocks/ordered_list_block.html'
class TableWithHeaderBlock(StructBlock): default_table_options = { 'minSpareRows': 0, 'startRows': 4, 'startCols': 4, 'colHeaders': False, 'rowHeaders': False, 'contextMenu': True, 'editor': 'text', 'stretchH': 'all', 'height': 150, 'renderer': 'text', 'autoColumnSize': False, 'mergeCells': True } number = CharBlock(title='Table number', required=False) title = CharBlock(title='Table title', required=False) table = UpdatedTableBlock(table_options=default_table_options, required=True) class Meta: image = 'pages/images/streamfield_blocks/table_with_header.jpg' template = 'pages/streamfield_blocks/table_with_header.html' def render(self, value, context=None): template = getattr(self.meta, 'template', None) if template and value.get('table', None): table_header = value['table']['data'][0] if value['table'].get( 'data', None) and len( value['table']['data']) > 0 and value['table'].get( 'first_row_is_table_header', False) else None first_col_is_header = value['table'].get('first_col_is_header', False) if context is None: new_context = {} else: new_context = dict(context) new_context.update({ 'self': value, self.TEMPLATE_VAR: value['table'], 'table_header': table_header, 'first_col_is_header': first_col_is_header, 'html_renderer': self.declared_blocks['table'].is_html_renderer(), 'data': value['table']['data'][1:] if table_header else value['table'].get('data', []) }) return render_to_string(template, new_context)
class GenericStreamBlock(StreamBlock): h2 = CharBlock(icon='title', classname='title') h3 = CharBlock(icon='title', classname='title') h4 = CharBlock(icon='title', classname='title') intro = RichTextBlock(icon='pilcrow') pullquote = PullQuoteBlock(icon='openquote') paragraph = RichTextBlock(icon='pilcrow') image = ImageBlock(icon='image', label='image') html = AlignedHTMLBlock(icon='code', label='html') two_columns = TwoColumns(icon='code', label='Two Columns')
class TeamMemberBlock(StructBlock): name = CharBlock() title = CharBlock(required=False) qualifications = CharBlock(required=False) image = ImageChooserBlock() links = ListBlock(LinkBlock(), required=False) class Meta: icon = 'user' template = 'blocks/team_member.html'
class LinkBlock(StructBlock): url = CharBlock(required=False) page = PageChooserBlock(required=False) label = CharBlock() style = LinkStyleChoiceBlock() class Meta: help_text = ''' Use either URL or page, if both are filled in URL takes precedence.''' template = 'cms/blocks/link_block.html'
class ContentStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow", label=u'简介') paragraph = RichTextBlock(icon="pilcrow", label=u'段落') aligned_image = ImageBlock(label=u'图片', icon="image") pullquote = PullQuoteBlock(label=u'引言') aligned_html = AlignedHTMLBlock(icon="code", label=u'HTML 代码') document = DocumentChooserBlock(icon="doc-full-inverse", label=u'请选择文本')
class AppStreamBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image", icon="image") pullquote = PullQuoteBlock() aligned_html = AlignedHTMLBlock(icon="code", label='Raw HTML') document = DocumentChooserBlock(icon="doc-full-inverse")
class ImageListBlock(StructBlock): title = CharBlock(required=False) items = ListBlock( StructBlock([('title', CharBlock()), ('subtitle', CharBlock()), ('description', RichTextBlock()), ('image', ImageChooserBlock()), ('page', PageChooserBlock(required=False))])) class Meta: template = 'cms/blocks/image_list_block.html'
class SidebarCallOutBlock(StructBlock): title = CharBlock() body = RichTextBlock(required=False) icon = CharBlock(required=False, help_text='Text block passed as the icon selected. ' 'Choose between Ionic Icons or FontAwesome.') links = ListBlock(LinkBlock(), required=False) class Meta: icon = 'radio-empty' template = 'blocks/sidebar_callout.html'