def test_render(self): block = ImageChooserBlock() html = block.render(self.image) expected_html = '<img alt="Test image" src="{}" width="640" height="480">'.format( self.get_image_filename(self.image, "original") ) self.assertHTMLEqual(html, expected_html)
class ClientsBlock(StructBlock): h3 = blocks.CharBlock(required=False) text = blocks.CharBlock(required=False) clients_list = CardsBlock(blocks.StructBlock([ ('page', blocks.PageChooserBlock(required=False)), ('link', blocks.CharBlock(required=False)), ('title', blocks.CharBlock(required=False)), ('image', ImageChooserBlock(required=False)) ])) blocks = CardsBlock(blocks.StructBlock([ ('text', blocks.CharBlock(required=False)), ('name', blocks.CharBlock(required=False)), ('company', blocks.CharBlock(required=False)), ('city', blocks.CharBlock(required=False)), ('image', ImageChooserBlock(required=False)) ])) class Meta: icon = 'user' template = "sections/clients_block.html"
class DefaultStreamPage(Page): body = StreamField([ ('text', CharBlock()), ('rich_text', RichTextBlock()), ('image', ImageChooserBlock()), ], default='') content_panels = [ FieldPanel('title'), StreamFieldPanel('body'), ]
class RightAlignedImage(blocks.StructBlock): left_column = blocks.StreamBlock([('paragraph', blocks.RichTextBlock())]) right_column = blocks.StreamBlock([ ('image', ImageChooserBlock()), ]) class Meta: template = 'blog/right_aligned_image.html' icon = 'image'
class ImagesBlock(blocks.StructBlock): images = blocks.ListBlock(ImageChooserBlock(required=False)) class Meta: template = 'wagtail_extensions/blocks/images.html' def get_context(self, value, parent_context=None): ctx = super().get_context(value, parent_context=parent_context) ctx['column_width'] = math.floor(12 / len(value.get('images', []))) return ctx
class ImageBlock(StructBlock): """ Custom `StructBlock` for utilizing images with associated caption and attribution data """ image = ImageChooserBlock(required=True) caption = CharBlock(required=False) attribution = CharBlock(required=False) class Meta: icon = 'image'
class ImageGridBlock(StructBlock): title = CharBlock(required=False) items = ListBlock( StructBlock([('image', ImageChooserBlock()), ('url', URLBlock(required=False)), ('page', PageChooserBlock(required=False))])) class Meta: help_text = ''' Use either URL or page, if both are filled in URL takes precedence.''' template = 'cms/blocks/image_grid_block.html'
class HomePage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('embed', EmbedBlock()) ]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ]
class UnorderedListBlock(blocks.StructBlock): bullet_icon = ImageChooserBlock( label = 'Afbeelding-icoon', help_text = 'Het afbeelding icoontje per bullet.', required=False, ) content = blocks.ListBlock( blocks.RichTextBlock(), label = 'Bullets', help_text = 'Inhoud van de bullet.', )
class QuoteBlock(blocks.StructBlock): quote = blocks.TextBlock( label='Citaat', required=True, max_length=150, ) quote_pos = blocks.ChoiceBlock( choices=( ('up', 'Boven'), ('under', 'Onder'), ), label='Positie quote', help_text='De positie van de quote (boven of onder het plaatje).', ) quote_size = blocks.ChoiceBlock( choices=( ('24px', '24px'), ('40px', '40px'), ), label='Quote tekstgrootte', help_text='De tekstgroote van de quote.', ) quote_background_color = ColorPickerBlock( label='Achtergrondkleur', required=False, help_text='De achtergrondkleur van de quote.') quote_color = ColorPickerBlock(label='Kleur tekst', required=False, help_text='De tekstkleur van de quote.') logo = ImageChooserBlock(required=False) name = blocks.CharBlock( label='Naam', max_length=50, help_text='Naam van de persoon achter het citaat.', ) company = blocks.CharBlock( label='Bedrijf', max_length=50, help_text='Naam van het bedrijf achter het citaat.', ) city = blocks.CharBlock(label='Plaats', max_length=50, help_text='Plaats') link = blocks.PageChooserBlock( label='Interne link', can_choose_root=True, required=False, )
class HomePage(Page): button = models.CharField(max_length=255) body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ]) content_panels = Page.content_panels + [ FieldPanel('button'), StreamFieldPanel('body') ]
class ActionBlock(blocks.StructBlock): action = blocks.CharBlock(verbose_name="Actie", help_text="Tekst wat linksboven in de afbeelding komt. Bijvoorbeeld: Blog") color = ColorPickerBlock( label = 'Achtergrond kleur', help_text='Achtergrond kleur voor actie', required = False, ) image = ImageChooserBlock() datum = blocks.DateBlock(required=False, help_text="Optioneel. Bijvoorbeeld voor blogs of speciale events.") title = blocks.CharBlock(verbose_name="Titel", help_text="Titel van je actieblok. Voorbeeld: Review: De nieuwe HP Latex 570") link = blocks.CharBlock(verbose_name="Link url", help_text="Vul hier een url handmatig in. Bijvoorbeeld: /contact/ of www.google.nl") link_text = blocks.CharBlock(verbose_name="Link tekst", help_text="Vul hier een url tekst handmatig in. Bijvoorbeeld: bekijk alle blogartikelen of bekijk alle reviews. ")
class OneColumnBlock(StructBlock): back_image = ImageChooserBlock(blank=True) background_size = ImageFormatChoiceBlock(choices=SIZE_CHOICES,default="auto") one_column = StreamBlock([ ('heading', CharBlock(classname="full title")), ('paragraph', RichTextBlock()), ], icon='arrow-left', label='Parallax content') class Meta: template = 'home/includes/one_column_block.html' icon = 'placeholder' label = 'One Column'
class EntryAbstract(models.Model): # body = RichTextField(verbose_name=_('body')) new_body = StreamField([ ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('embed', EmbedBlock()), ('CodeBlock', ContentStreamBlock()), ]) tags = ClusterTaggableManager(through='puput.TagEntryPage', blank=True) date = models.DateTimeField(verbose_name=_("Post date"), default=datetime.datetime.today) header_image = models.ForeignKey( get_image_model_path(), verbose_name=_('Header image'), null=True, blank=True, on_delete=models.SET_NULL, related_name='+', ) categories = models.ManyToManyField('puput.Category', through='puput.CategoryEntryPage', blank=True) excerpt = RichTextField( verbose_name=_('excerpt'), blank=True, help_text=_( "Entry excerpt to be displayed on entries list. " "If this field is not filled, a truncate version of body text will be used." )) num_comments = models.IntegerField(default=0, editable=False) content_panels = [ MultiFieldPanel( [ FieldPanel('title', classname="title"), ImageChooserPanel('header_image'), # FieldPanel('body', classname="full"), FieldPanel('excerpt', classname="full"), StreamFieldPanel('new_body'), ], heading=_("Content")), MultiFieldPanel([ FieldPanel('tags'), InlinePanel('entry_categories', label=_("Categories")), InlinePanel('related_entrypage_from', label=_("Related Entries"), panels=[PageChooserPanel('entrypage_to')]), ], heading=_("Metadata")), ] class Meta: abstract = True
class TeaserImageBlock(StructBlock): image = ImageChooserBlock(required=False, help_text='Recommended minimal width: 737px') position = ChoiceBlock( choices=[ ('top', 'Top'), ('left', 'Left'), ('right', 'Right'), ], required=False, ) large = BooleanBlock(required=False)
class LandingPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname='full title')), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock(icon='image')), ('two_columns', TwoColumnBlock()), ('embedded_video', EmbedBlock(icon='media')) ], null=True, blank=True) content_panels = Page.content_panels + [ StreamFieldPanel('body') ]
class ImageWithCaptionBlock(blocks.StructBlock): image = ImageChooserBlock() text = blocks.CharBlock( required=True, max_length=180, help_text='Geef de afbeelding een korte beschrijving') class Meta: template = 'home/blocks/image_with_caption.html' icon = 'picture' label = 'Afbeelding'
class ResponsiveImageBlock(blocks.StructBlock): image = ImageChooserBlock() height = blocks.IntegerBlock( min_value=1, default=400, ) class Meta: label = _('Responsive Image') icon = 'fa-picture-o' template = 'blocks/image.html' group = _('Basic')
class OverlayTeaserBlock(StructBlock): title = blocks.CharBlock() content = RichTextBlock(required=False) image = ImageChooserBlock(required=True, help_text='Recommended minimal width: 737px') page = PageChooserBlock( required=False, help_text='Links to the original page (in "{}") will automatically ' 'point to translated pages (if they exist) in other ' 'languages. Links to a translation will always point to that ' 'translated page, in all languages.'.format( TranslatablePageMixin.original_lang_code)) link = blocks.URLBlock(required=False) link_text = blocks.CharBlock(required=False) top_box = blocks.BooleanBlock(required=False, default=False) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) page = value.get('page') if page is not None: page = TranslatablePageMixin.get_translated_page(page.specific) link = value.get('link') image = value.get('image') link_text = value.get('link_text') or _('Link') top = value.get('top_box') context.update({ 'title': value.get('title'), 'description': value.get('content'), 'style': 'box', 'links': [ { 'href': page.url if page else link, 'text': link_text, 'external': not bool(page), }, ], 'imgsrc': image.get_rendition('max-1200x1200').url if image else '', 'flapmd': True, 'topposition': top, }) return context class Meta: icon = 'link' label = 'Large Image Teaser' template = 'widgets/overlay-teaser-widgetchooser.html' help_text = 'Choose either a page or an external link'
class BigTeaserBlock(StructBlock): title = CharBlock(required=True) subtitle = CharBlock(required=False) picture = ImageChooserBlock() text = RichTextBlock() external_link = URLBlock( required=False, help_text="Will be ignored if an internal link is provided") internal_link = PageChooserBlock( required=False, help_text='If set, this has precedence over the external link.') from_date = DateBlock(required=False) to_date = DateBlock(required=False) class Meta: icon = 'fa fa-list-alt' template = 'blocks/big_teaser_block.html' def __init__(self, wideimage=False, local_blocks=None, **kwargs): super().__init__(local_blocks=local_blocks, **kwargs) self.wideimage = wideimage def get_context(self, value, parent_context=None): context = super(BigTeaserBlock, self).get_context(value, parent_context=parent_context) context['super_title'] = value.get('title') image = value.get('picture') rendition = image.get_rendition('max-800x800') context['image'] = {'url': rendition.url, 'name': image.title} if value.get('internal_link'): context['href'] = value.get('internal_link').url else: context['href'] = value.get('external_link') if context['href']: context['text_right_link'] = True context['text_right_link_text'] = 'Learn more' context.update({ 'title': value.get('subtitle'), 'description': value.get('text'), 'divider': True, 'calendaricon': True, }) if value.get('from_date') and value.get('to_date'): context['date'] = '"{} to {}"'.format( formats.date_format(value.get('from_date'), "SHORT_DATE_FORMAT"), formats.date_format(value.get('to_date'), "SHORT_DATE_FORMAT")) context['wideimage'] = self.wideimage return context
class LogosBlock(blocks.StructBlock): logos = blocks.ListBlock( blocks.StructBlock([ ('image', ImageChooserBlock()), ('link', blocks.URLBlock(required=False)), ])) class Meta: label = _('Logos') icon = 'fa-pied-piper' template = 'blocks/logos.html' group = _('Noyce')
class Halves(blocks.StructBlock): """ HalvesBlock is an example of a sub-block / component / pre-defined collection of HTML elements. Using StructBlock sets this overall block to have a specific predefined format. This block can only consist of photo - title - text, and these fields are required. """ one_of_two = blocks.StructBlock([ ('photo', ImageChooserBlock(classname="img")), ('title', blocks.CharBlock(required=True, classname="title")), ('text', blocks.RichTextBlock())]) two_of_two = blocks.StructBlock([ ('photo', ImageChooserBlock(classname="img")), ('title', blocks.CharBlock(required=True, classname="title")), ('text', blocks.RichTextBlock())]) class Meta: template = 'home/blocks/halves.html' icon = 'placeholder'
class CommonQuoteBlock(blocks.StructBlock): """ Block for rich text quotes """ quote = blocks.RichTextBlock(editor='simple', required=False) author = blocks.CharBlock(required=False) author_title = blocks.CharBlock(required=False) image = ImageChooserBlock(required=False) class Meta: icon = 'openquote' template = 'blocks/quote.html'
class HeroBlock(StructBlockWithStyle): image = ImageChooserBlock(required=True) description = blocks.RawHTMLBlock(required=True) image_display_setting = blocks.ChoiceBlock( choices=[('background', 'Cover the whole Hero as a background'), ('icon', 'Center the image in the middle of the hero block')]) text_color = blocks.CharBlock(help_text='Enter a color for the text.') class Meta: template = 'common/blocks/hero_block.html' icon = 'fa-star' label = 'Hero Block'
class SimplePage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('embed', EmbedBlock()), ('rawHtml', blocks.RawHTMLBlock()), ('medailon', blocks.StructBlock( [ ('title', blocks.CharBlock(required=True)), ('pic', ImageChooserBlock(required=True)), ('description', blocks.RichTextBlock(required=True)), ], template='blocks/medailon.html', icon='user' )) ]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ]
class TransformedImage(blocks.StructBlock): image = ImageChooserBlock() alignment = blocks.ChoiceBlock([ ("left", "Left"), ("center", "Center"), ("right", "Right") ]) width = NumberBlock(initial=100, label="Width in percentage", help_text="Percentage") class Meta: icon = 'image' template = 'home/transformed_image.html'
class Gallery(blocks.StructBlock): images = blocks.ListBlock(ImageChooserBlock()) alignment = blocks.ChoiceBlock([ ("left", "Left"), ("center", "Center"), ("right", "Right") ]) width = NumberBlock(initial=100, label="Width in percentage", help_text="Percentage") class Meta: icon = 'image' template = 'home/gallery.html'
class GoodToKnowPage(Page): body = StreamField( [ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('TwoColumnBlock', TwoColumnBlock()), ], default="") content_panels = Page.content_panels + [ StreamFieldPanel('body'), ]
class ImageNotesBlock(blocks.StructBlock): """ Блок картинки, который выводится слева от статьи Используется блок подписи """ image = ImageChooserBlock(label='Фотография') title = blocks.CharBlock(label='Заголовок', required=False) notes = blocks.ListBlock( NoteBlock(), label='Подписи', )
def __init__(self, block_types=None, **kwargs): block_types = [ ('Heading', blocks.CharBlock(icon="title", classname="heading")), ('Paragraph', blocks.RichTextBlock(icon="doc-full")), ('Image', ImageChooserBlock(icon="image")), ('Embed', EmbedBlock(icon="site")), ('List', blocks.ListBlock(blocks.RichTextBlock(label="item"), icon="list-ul")), ] super(BodyField, self).__init__(block_types, **kwargs)
class MediaTextOverlayBlock(blocks.StructBlock): title = blocks.CharBlock(required=False, label="Title Text", max_length=255, help_text="Appears above the module.") image = ImageChooserBlock() logo = ImageChooserBlock(label="Title Logo", required=False) text = blocks.RichTextBlock(max_length=75, required=False, features=[ "bold", "italic", "ol", "ul", "link", "document-link", "justify" ]) link = LinkBlock(required=False) customisation = CustomisationBlock(required=False) def clean(self, value): if value['title'] and value['logo']: error_messages = ["Please choose only one of logo or title."] raise ValidationError( "Validation error in MediaTextOverlayBlock", params={ 'title': error_messages, 'logo': error_messages }, ) if not value['title'] and not value['logo']: error_messages = ["Please choose a logo or title."] raise ValidationError( "Validation error in MediaTextOverlayBlock", params={ 'title': error_messages, 'logo': error_messages }, ) return super().clean(value) class Meta: icon = "image" template = "blocks/media_text_overlay_block.html"
def test_render_missing(self): block = ImageChooserBlock() html = block.render(self.bad_image) expected_html = '<img alt="missing image" src="/media/not-found" width="0" height="0">' self.assertHTMLEqual(html, expected_html)