예제 #1
0
    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)
예제 #2
0
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"
예제 #3
0
class DefaultStreamPage(Page):
    body = StreamField([
        ('text', CharBlock()),
        ('rich_text', RichTextBlock()),
        ('image', ImageChooserBlock()),
    ], default='')

    content_panels = [
        FieldPanel('title'),
        StreamFieldPanel('body'),
    ]
예제 #4
0
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'
예제 #5
0
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
예제 #6
0
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'
예제 #7
0
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'
예제 #8
0
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'),
    ]
예제 #9
0
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.',
    )
예제 #10
0
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,
    )
예제 #11
0
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')
    ]
예제 #12
0
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. ")
예제 #13
0
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'
예제 #14
0
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
예제 #15
0
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)
예제 #16
0
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')
    ]
예제 #17
0
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'
예제 #18
0
파일: models.py 프로젝트: Dekker1/moore
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')
예제 #19
0
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'
예제 #20
0
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
예제 #21
0
파일: models.py 프로젝트: Dekker1/moore
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')
예제 #22
0
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'
예제 #23
0
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'
예제 #24
0
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'
예제 #25
0
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'),
    ]
예제 #26
0
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'
예제 #27
0
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'
예제 #28
0
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'),
    ]
예제 #29
0
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)
예제 #31
0
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"
예제 #32
0
    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)