Пример #1
0
    def test_clean_invalid_url(self, get_embed):
        get_embed.side_effect = EmbedNotFoundException

        non_required_block = EmbedBlock(required=False)

        with self.assertRaises(ValidationError):
            non_required_block.clean(
                EmbedValue('http://no-oembed-here.com/something'))

        required_block = EmbedBlock()

        with self.assertRaises(ValidationError):
            required_block.clean(
                EmbedValue('http://no-oembed-here.com/something'))
Пример #2
0
class VideoBlock(blocks.StructBlock):
    video = EmbedBlock(required=False, label='Video URL')

    class Meta:
        icon = "media"
        template = 'wagtail_guide/streamfield/blocks/video_block.html'
        label = "Video"
Пример #3
0
    def test_render_within_structblock(self, get_embed):
        """
        When rendering the value of an EmbedBlock directly in a template
        (as happens when accessing it as a child of a StructBlock), the
        proper embed output should be rendered, not the URL.
        """
        get_embed.return_value = Embed(html="<h1>Hello world!</h1>")

        block = blocks.StructBlock([
            ("title", blocks.CharBlock()),
            ("embed", EmbedBlock()),
        ])

        block_val = block.to_python({
            "title": "A test",
            "embed": "http://www.example.com/foo"
        })

        temp = template.Template("embed: {{ self.embed }}")
        context = template.Context({"self": block_val})
        result = temp.render(context)

        self.assertIn("<h1>Hello world!</h1>", result)

        # Check that get_embed was called correctly
        get_embed.assert_any_call("http://www.example.com/foo", None, None)
Пример #4
0
class BoxBody(blocks.StreamBlock):
    paragraph = blocks.RichTextBlock()
    inline_image = CustomImageBlock(icon='image')
    video = EmbedBlock(icon='media')
    iframe = IframeBlock(icon="link")
    datawrapper = DatawrapperBlock(icon="code")
    dataviz = ReportDataVizBlock(icon="code")
Пример #5
0
class Embarque(TemplatedBlock):
    class Meta:
        icon = 'media'
        group = 'Contenu média'
        label = 'média embarqué'

    media = EmbedBlock(icon='link', help_text='Lien vers le média embarqué.')
class ThesisDiscipline(models.Model):
    name = models.CharField(max_length=100, blank=False, unique=True)
    introduction = RichTextField(blank=True)
    description_legacy = RichTextField(blank=True)
    topics = StreamField(
        [
            ("heading", blocks.CharBlock(classname="full title")),
            (
                "heading_linkable",
                HeadingBlock(
                    help_text="heading text",
                    features=[
                        "bold", "italic", "h1", "h2", "h3", "h4", "h5", "h6"
                    ],
                ),
            ),
            ("paragraph", AllHeadingsRichTextBlock()),
            ("image", ImageChooserBlock()),
            ("embed", EmbedBlock()),
            ("rawHtml", blocks.RawHTMLBlock()),
        ],
        null=True,
        blank=True,
    )

    panels = [
        FieldPanel("name"),
        FieldPanel("introduction"),
        StreamFieldPanel("topics"),
        FieldPanel("description_legacy"),
    ]

    def __str__(self):
        return self.name
class EmbedBlock(blocks.StructBlock):
    embed = EmbedBlock(required=True, help_text='Add media link')

    class Meta:
        template = 'streams/embed_block.html'
        icon = 'media'
        label = "Embed Media"
Пример #8
0
class BlogStreamBlock(StreamBlock):
    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")
    embed = EmbedBlock(icon="media", label="Embed Media URL")
Пример #9
0
class TwoColumnGeneralPage(AbstractBase):
    body = StreamField(block_types=([
        ('green_heading',
         Heading(classname='full title',
                 help_text=_('Text will be green and centered'))),
        ('emphatic_text',
         EmphaticText(classname='full title',
                      help_text=_('Text will be red, italic and centered'))),
        ('paragraph', AlignedParagraphBlock()),
        ('image', ImageChooserBlock()),
        ('document', DocumentChooserBlock()),
        ('two_columns', TwoColumnBlock()),
        ('embedded_video', EmbedBlock(icon='media')),
        ('html', blocks.RawHTMLBlock()),
        ('dropdown_image_list', ImageListDropdownInfo()),
        ('dropdown_button_list', ButtonListDropdownInfo()),
    ]),
                       null=True,
                       blank=True)

    content_panels = AbstractBase.content_panels + [
        StreamFieldPanel('body'),
    ]

    search_fields = AbstractBase.search_fields + [index.SearchField('body')]
Пример #10
0
class BaseStreamBlock(StreamBlock):
    """
    Define the custom blocks that `StreamField` will utilize
    """
    heading_block = HeadingBlock()
    paragraph_block = RichTextBlock(
        icon="paragraph",
        template="blocks/paragraph_block.html"
    )
    image_block = ImageBlock()
    block_quote = BlockQuote()
    code_block = CodeBlock(
        help_text='Insert code',
        icon="fa-code",
        template="blocks/code_block.html")
    embed_block = EmbedBlock(
        help_text='Insert an embed URL e.g https://www.youtube.com/watch?v=OrOE2y0Fj2w',
        icon="fa-s15",
        template="blocks/embed_block.html")
    map1_block = Map1Block(
        help_text='Insert caption for map',
        icon="fa-globe-asia",
        template="blocks/tonga1_block.html")
    map2_block = Map2Block(
        help_text='Insert caption for map',
        icon="fa-globe-asia",
        template="blocks/tonga2_block.html")
    map3_block = Map3Block(
        help_text='Insert caption for map',
        icon="fa-globe-asia",
        template="blocks/tonga3_block.html")
Пример #11
0
class VideoBlock(StructBlock):
    video = EmbedBlock()

    class Meta:
        template = "blocks/video_card_block.html"
        icon = "media"
        label = "Embed Video"
Пример #12
0
class Sidebar(models.Model):
    name = models.CharField(_("Name"), max_length=50)
    fixed = models.BooleanField(_("Fixed Position"), default=False)
    body = StreamField([
        # (_('Heading'), blocks.CharBlock(classname="full title")),
        (_('Rich_Text'), blocks.RichTextBlock()),
        (_('Text'), blocks.TextBlock()),
        (_('Image'), ImageChooserBlock(icon="image")),
        # (_('Image(aligned)'), AlignedImageBlock()),
        (_('Embedded_Video'), EmbedBlock(icon="media")),
        (_('HTML'), blocks.RawHTMLBlock()),
        # (_('Quote'), blocks.BlockQuoteBlock()),
        # (_('Email_Form'), blocks.EmailBlock()),
        # (_('OptinForm'), OptinChooserBlock()),
        (_('Optin'), OptinChooserBlock('optin.Optin')),
        (_('Aligned_Image'), AlignedImageBlock()),
    ])

    panels = [
        FieldPanel('name'),
        FieldPanel('fixed'),
        StreamFieldPanel('body'),
    ]

    def __str__(self):
        return self.name
Пример #13
0
class FlexPage(ExportModelOperationsMixin("flex_page"), MetadataPageMixin,
               Page):
    body = StreamField(
        [
            ("header", MyHeaderBlock()),
            ("list", ListBlock()),
            ("image_text_overlay", ImageTextOverlayBlock()),
            ("cropped_images_with_text", CroppedImagesWithTextBlock()),
            ("list_with_images", ListWithImagesBlock()),
            ("thumbnail_gallery", ThumbnailGalleryBlock()),
            ("chart", ChartBlock()),
            ("map", MapBlock()),
            ("image_slider", ImageSliderBlock()),
            ("form", WagtailFormBlock()),
            ("Parallax", ParallaxBlock()),
            ("Code", MyCodeBlock()),
            ("Timeline", TimelineBlock()),
            ("Text", blocks.RichTextBlock()),
            ("Quote", blocks.BlockQuoteBlock()),
            ("Embed", EmbedBlock()),
            ("Document", DocumentChooserBlock()),
        ],
        blank=True,
    )
    author_twitter_handle = models.CharField(max_length=15)
    content_panels = Page.content_panels + [
        StreamFieldPanel("body", classname="Full"),
        FieldPanel("author_twitter_handle"),
    ]
Пример #14
0
class FlexPage(Page):
    """Flexible page class."""

    template = "flex/flex_page.html"
    # embed = EmbedBlock

    content = StreamField([
        ("title_and_text", blocks.TitleAndTextBlock()),
        ("full_richtext", blocks.RichTextBlock()),
        ("simple_richtext", blocks.SimpleRichTextBlock()),
        ("embed_block", EmbedBlock()),
        ("html_block", blocks.RawHTMLBlock()),
        ("image_chooser_block", ImageChooserBlock()),
        ("cards", blocks.CardBlock()),
        ("carousel_images", blocks.CarouselImages()),
    ],
                          null=True,
                          blank=True)

    subtitle = models.CharField(max_length=100, null=True, blank=True)

    content_panels = Page.content_panels + [
        StreamFieldPanel("content"),
    ]

    class Meta:  # noqa
        verbose_name = "Flexible Page"
        verbose_name_plural = "Flexible Pages"
Пример #15
0
class GdprEmbedBlock(CollapsibleFieldsMixin, blocks.StructBlock):
    heading = blocks.CharBlock(**heading_block_kwargs)
    embed = EmbedBlock()
    caption = blocks.CharBlock(**caption_block_kwargs)
    description = blocks.TextBlock(**description_block_kwargs)
    show_gdpr_message = blocks.BooleanBlock(default=True, required=False)
    width = blocks.CharBlock(
        required=False, default="", validators=[css_length_validator]
    )
    height = blocks.CharBlock(
        required=False, default="", validators=[css_length_validator]
    )

    fields = [
        "heading",
        "embed",
        "show_gdpr_message",
        {"label": _("Card"), "fields": ["caption", "description"]},
        {"label": _("Settings"), "fields": ["align", "width", "height"]},
    ]

    class Meta:
        icon = "media"
        template = "xr_embeds/blocks/gdpr_embed.html"
        value_class = XrStructValue
Пример #16
0
class NewsItem(AbstractNewsItem):
    # NewsItem is a normal Django model, *not* a Wagtail Page. RichTextField
    # Add any fields required for your page.
    # It already has ``date`` field, and a link to its parent ``NewsIndex`` Page
    headline = models.CharField(max_length=255)
    byline = models.CharField(max_length=255)
    lead = StreamField([
        ('lead', blocks.RichTextBlock()),
    ], blank=True)
    body = StreamField([
        ('heading', blocks.CharBlock(form_classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('blockquote', blocks.BlockQuoteBlock()),
        ('svg', SvgChooserBlock()),
        ('image', ImageChooserBlock()),
        ('embed', EmbedBlock()),
        ('button', ButtonBlock()),
    ],
                       blank=True)
    author = StreamField([
        ('author', PersonBlock()),
    ], blank=True)

    panels = [
        FieldPanel('headline', classname='full title'),
        FieldPanel('byline', classname='byline'),
        StreamFieldPanel('lead', classname='lead'),
        StreamFieldPanel('body', classname='body'),
        StreamFieldPanel('author', classname='author'),
    ] + AbstractNewsItem.panels

    def __str__(self):
        return self.headline
class BlogPage(Page):
    date = models.DateField("Post date", null=True, blank=False)
    blog_image = models.ForeignKey('wagtailimages.Image',
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL)

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]
    intro = models.CharField(max_length=250, null=True, blank=False)
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title", icon="title")),
        ('paragraph', blocks.RichTextBlock(icon="pilcrow")),
        ('embed', EmbedBlock(icon="media")),
    ],
                       null=True,
                       blank=False)

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        ImageChooserPanel('blog_image'),
        MultiFieldPanel([
            InlinePanel("blog_authors", label="Author", min_num=1, max_num=5)
        ],
                        heading="Author(s)"),
        FieldPanel('intro'),
        StreamFieldPanel('body'),
        InlinePanel('gallery_images', label="Gallery images"),
    ]
Пример #18
0
class ParallaxHeaderBlock(blocks.StructBlock):
    background = ImageChooserBlock(blank=True)
    title = blocks.CharBlock(blank=True)
    body = blocks.StreamBlock(
        [
            (_('Rich_Text'), blocks.RichTextBlock()),
            (_('Text'), blocks.TextBlock()),
            (_('Image'), ImageChooserBlock(icon="image")),
            # (_('Image(aligned)'), AlignedImageBlock()),
            (_('Embedded_Video'), EmbedBlock(icon="media")),
            (_('HTML'), blocks.RawHTMLBlock()),
            (_('Quote'), blocks.BlockQuoteBlock()),
            (_('Optin'), OptinChooserBlock('optin.Optin')),
            (_('Code'), CodeBlock(label='Code Editor')),
            (_('Bootstrap_Row'), BootstrapRow()),
            (_('Bootstrap_Col'), BootstrapCol()),
            (_('Aligned_Image'), AlignedImageBlock()),
        ],
        blank=True,
        null=True,
        required=False)

    class Meta:
        icon = 'form'
        label = 'Parallax Header'
        template = 'blog/blocks/parallax_header.html'
Пример #19
0
class BootstrapCol(blocks.StructBlock):
    width = blocks.IntegerBlock(max_value=12,
                                min_value=0,
                                help_text='0 = auto',
                                default=0)
    alignment = blocks.ChoiceBlock(choices=[
        ('center', 'Center'),
        ('right', 'Right'),
        ('left', 'Left'),
    ],
                                   default='center')
    vertical_center = blocks.BooleanBlock(default=False,
                                          blank=True,
                                          required=False)
    body = blocks.StreamBlock([
        (_('Rich_Text'), blocks.RichTextBlock()),
        (_('Text'), blocks.TextBlock()),
        (_('Image'), ImageChooserBlock(icon="image")),
        (_('Embedded_Video'), EmbedBlock(icon="media")),
        (_('HTML'), blocks.RawHTMLBlock()),
        (_('Quote'), blocks.BlockQuoteBlock()),
        (_('Optin'), OptinChooserBlock('optin.Optin')),
        (_('Code'), CodeBlock(label='Code Editor')),
        (_('Aligned_Image'), AlignedImageBlock()),
    ],
                              blank=True,
                              null=True,
                              required=False)

    class Meta:
        icon = 'grip'
        label = 'Bootstrap Col'
        template = 'blog/blocks/bootstrap_col.html'
class CustomContent(index.Indexed, models.Model):
    title = models.CharField(max_length=255, unique=True)
    body = StreamField([('heading', HeadingBlock()),
                        ('paragraph', blocks.RichTextBlock()),
                        ('markdown', MarkDownBlock(rows=10)),
                        ('html', blocks.RawHTMLBlock()),
                        ('image', ImageBlock()),
                        ('document', DocumentChooserBlock()),
                        ('pullquote', QuoteBlock()), ('embed', EmbedBlock()),
                        ('two_column', TwoColumnBlock())],
                       null=True,
                       blank=True)

    class Meta:
        ordering = [
            'title',
        ]
        verbose_name = 'custom content module'

    # search
    search_fields = [
        index.SearchField('title', partial_match=True),
    ]

    # editor panels configuration
    panels = [
        FieldPanel('title'),
        StreamFieldPanel('body'),
    ]

    def __str__(self):
        return self.title
Пример #21
0
class ComplexPage(BasePage):
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock(
            features=[
                'ol',
                'ul',
                'blockquote',
                'bold',
                'italic',
                'superscript',
                'subscript',
                'strikethrough',
                'code',
                'link',
                'image',
                'document-link',
            ],
        )),
        ('image', ImageBlock()),
        ('embed', EmbedBlock()),
        ('media', MediaBlock(icon='media')),
        ('raw_HTML', blocks.RawHTMLBlock(required=False)),
        ('danger', blocks.RawHTMLBlock(label='DANGER!', required=False)),
    ])
    page_message = RichTextField()

    content_panels = Page.content_panels + [
        FieldPanel('page_message'),
        StreamFieldPanel('body'),
    ]
Пример #22
0
class StandardPage(Page):
    """
    A generic content page. On this demo site we use it for an about page but
    it could be used for any type of page content that only needs a title,
    image, introduction and body field
    """

    introduction = models.TextField(help_text='Text to describe the page',
                                    blank=True)
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text=
        'Landscape mode only; horizontal width between 1000px and 3000px.')
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('embed', EmbedBlock(classname="responsive-object")),
    ])

    content_panels = Page.content_panels + [
        FieldPanel('introduction', classname="full"),
        StreamFieldPanel('body'),
        ImageChooserPanel('image'),
    ]
class OutlineThesisSimple(Page, NestedOutline):
    outline_title = RichTextField()
    body = StreamField([
        ("heading", blocks.CharBlock(classname="full title")),
        (
            "heading_linkable",
            HeadingBlock(
                help_text="heading text",
                features=["h1", "h2", "h3", "h4", "h5", "h6"],
            ),
        ),
        ("paragraph", blocks.RichTextBlock()),
        ("image", ImageChooserBlock()),
        ("embed", EmbedBlock()),
        ("rawHtml", blocks.RawHTMLBlock()),
    ])

    content_panels = Page.content_panels + [
        FieldPanel("outline_title"),
        StreamFieldPanel("body"),
    ]

    parent_page_types = ["theses.ThesisIndexPage"]

    def get_context(self, request):
        context = super(OutlineThesisSimple, self).get_context(request)
        context["contactForm"] = SimpleContactForm
        context["outline"] = self.get_outline(self.body.stream_data)
        return context
Пример #24
0
class VideoBlock(blocks.StructBlock):
    """
    An embeddable video block.
    """

    video = EmbedBlock(help_text="Embed a video from Youtube")
    caption = blocks.CharBlock(max_length=50,
                               required=False,
                               help_text="Optional caption for video")

    # custom init so column can be passed to template
    def __init__(self,
                 required=False,
                 label=None,
                 help_text=None,
                 *args,
                 **kwargs):
        self._required = required
        self._help_text = help_text
        self._label = label
        self.column = kwargs.get("column")
        super().__init__(*args, **kwargs)

    def get_context(self, value, parent_context=None):
        ctx = super().get_context(value, parent_context=parent_context)
        ctx["column"] = self.column
        return ctx

    class Meta:
        template = "streams/embed_block.html"
        icon = "media"
        label = "Video Embed"
        help_text = "Embed a video"
Пример #25
0
class BlogPage(Page):
    date = models.DateField('Post date')
    intro = models.CharField(max_length=250)

    content = StreamField([
        ("rich_text", RichTextBlock(template="home/blocks/rich_text.html")),
        ("image", ImageChooserBlock()),
        ("embed", EmbedBlock()),
        ("raw_html", RawHTMLBlock()),
        ("columns", ColumnBlock()),
        ("mathjax", MathjaxBlock()),
        ('code', CodeBlock())
    ])

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('content')
    ]

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        MultiFieldPanel([InlinePanel("authors", min_num=1)], heading="Auteurs"),
        FieldPanel('intro'),
        StreamFieldPanel('content')
    ]
Пример #26
0
class BaseStreamBlock(StreamBlock):
    """
    Define the custom blocks that `StreamField` will utilize
    """

    code_block = CodeBlock()
    heading_block = HeadingBlock()
    paragraph_block = RichTextBlock(icon="fa-paragraph",
                                    template="blocks/paragraph_block.html")
    paragraph_dev_block = RichTextBlock(
        icon="fa-paragraph",
        template="blocks/paragraph_block.html",
        features=[
            "h2",
            "h3",
            "bold",
            "italic",
            "link",
            "code",
            "superscript",
            "subscript",
            "strikethrough",
        ],
    )
    image_block = ImageBlock()
    block_quote = BlockQuote()
    embed_block = EmbedBlock(
        help_text=
        "Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks",
        icon="fa-s15",
        template="blocks/embed_block.html",
    )
Пример #27
0
class ExploreMapText(models.Model):
    title = models.CharField(max_length=255, blank=True, null=True)
    text_before = StreamField([
        ('text', blocks.RichTextBlock()),
        ('heading', blocks.CharBlock()),
        ('html', blocks.RawHTMLBlock()),
    ],
                              null=True)
    text_after = StreamField([
        ('inline_image', ImageChooserBlock()),
        ('text', blocks.RichTextBlock()),
        ('heading', blocks.CharBlock()),
        ('html', blocks.RawHTMLBlock()),
        ('embed', EmbedBlock(icon='media')),
    ],
                             null=True)

    panels = [
        FieldPanel('title'),
        StreamFieldPanel('text_before'),
        StreamFieldPanel('text_after'),
    ]

    def __str__(self):
        return "Explore Map Text"

    def clean(self):
        if self.id is None and self._meta.model.objects.exists():
            raise ValidationError(
                'The Explore page can only have one set of text blocks.')
Пример #28
0
class Optin(models.Model):
    name = models.CharField(_("Name"), max_length=50)
    blue_background = models.BooleanField(_("Blue_background"),
                                          blank=True,
                                          default=False)
    dont_hide_from_subscribers = models.BooleanField(
        _("Dont_Hide_From_Subscribers"), blank=True, default=False)

    body = StreamField([
        (_('Bootstrap_Row'), BootstrapRow()),
        (_('Bootstrap_Col'), BootstrapCol()),
        (_('Rich_Text'), blocks.RichTextBlock()),
        (_('Text'), blocks.TextBlock()),
        (_('Image'), ImageChooserBlock(icon="image")),
        # (_('Image(aligned)'), AlignedImageBlock()),
        (_('Embedded_Video'), EmbedBlock(icon="media")),
        (_('HTML'), blocks.RawHTMLBlock()),
        (_('Email_Optin_Form'), EmailOptinFormBlock()),
        (_('Aligned_Image'), AlignedImageBlock()),
        (_('Email_Optin_CTA_Form'), EmailOptinCTABlock()),
    ])

    panels = [
        FieldPanel('name'),
        FieldPanel('blue_background'),
        FieldPanel('dont_hide_from_subscribers'),
        StreamFieldPanel('body'),
    ]

    def __str__(self):
        return self.name
Пример #29
0
    def test_render_within_structblock(self, get_embed):
        """
        When rendering the value of an EmbedBlock directly in a template
        (as happens when accessing it as a child of a StructBlock), the
        proper embed output should be rendered, not the URL.
        """
        get_embed.return_value = Embed(html='<h1>Hello world!</h1>')

        block = blocks.StructBlock([
            ('title', blocks.CharBlock()),
            ('embed', EmbedBlock()),
        ])

        block_val = block.to_python({
            'title': 'A test',
            'embed': 'http://www.example.com/foo'
        })

        temp = template.Template('embed: {{ self.embed }}')
        context = template.Context({'self': block_val})
        result = temp.render(context)

        self.assertIn('<h1>Hello world!</h1>', result)

        # Check that get_embed was called correctly
        get_embed.assert_any_call('http://www.example.com/foo')
Пример #30
0
class EmbedTitleBlock(blocks.StructBlock):
    title = blocks.CharBlock(required=False)
    embed = EmbedBlock()

    class Meta:
        icon = "media"
        template = 'wagtail_guide/streamfield/blocks/embed_block.html'