Пример #1
0
    def test_features_option_on_rich_text_block(self):
        # a 'features' list passed on the RichTextBlock
        # should override the list in OPTIONS
        block = RichTextBlock(features=["h2", "embed"])

        form_html = block.render_form(block.to_python("<p>hello</p>"), "body")

        self.assertIn('"type": "header-two"', form_html)
        self.assertIn('"type": "EMBED"', form_html)
        self.assertNotIn('"type": "IMAGE""', form_html)
        self.assertNotIn('"type": "ordered-list-item""', form_html)
Пример #2
0
class StreamPage(Page):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ExtendedImageChooserBlock()),
            (
                "product",
                StructBlock([
                    ("name", CharBlock()),
                    ("price", CharBlock()),
                ]),
            ),
            ("raw_html", RawHTMLBlock()),
            (
                "books",
                StreamBlock([
                    ("title", CharBlock()),
                    ("author", CharBlock()),
                ]),
            ),
        ],
        use_json_field=False,
    )

    api_fields = ("body", )

    content_panels = [
        FieldPanel("title"),
        FieldPanel("body"),
    ]

    preview_modes = []
Пример #3
0
class DefaultRichBlockFieldPage(Page):
    body = StreamField(
        [
            ("rich_text", RichTextBlock()),
        ],
        use_json_field=False,
    )

    content_panels = Page.content_panels + [FieldPanel("body")]
Пример #4
0
class JSONStreamModel(models.Model):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        use_json_field=True,
    )
Пример #5
0
class OneToOnePage(Page):
    """
    A Page containing a O2O relation.
    """

    body = RichTextBlock(blank=True)
    page_ptr = models.OneToOneField(Page,
                                    parent_link=True,
                                    related_name="+",
                                    on_delete=models.CASCADE)
Пример #6
0
class JSONMinMaxCountStreamModel(models.Model):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        min_num=2,
        max_num=5,
        use_json_field=True,
    )
Пример #7
0
class BaseStreamBlock(StreamBlock):
    """
    Define the custom blocks that `StreamField` will utilize
    """
    link_block = CaptionedPageLink()
    integer = IntegerBlock(required=True)
    page = PageChooserBlock()
    stream = AnotherStreamBlock()
    rich_text = RichTextBlock()
    list_of_pages = ListBlock(PageChooserBlock())
    list_of_captioned_pages = ListBlock(CaptionedPageLink())
Пример #8
0
class CustomRichBlockFieldPage(Page):
    body = StreamField(
        [
            ("rich_text", RichTextBlock(editor="custom")),
        ],
        use_json_field=False,
    )

    content_panels = [
        FieldPanel("title", classname="full title"),
        FieldPanel("body"),
    ]
Пример #9
0
class InlineStreamPageSection(Orderable):
    page = ParentalKey("tests.InlineStreamPage",
                       related_name="sections",
                       on_delete=models.CASCADE)
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        use_json_field=False,
    )
    panels = [FieldPanel("body")]
Пример #10
0
class DefaultStreamPage(Page):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        default="",
        use_json_field=False,
    )

    content_panels = [
        FieldPanel("title"),
        FieldPanel("body"),
    ]
Пример #11
0
class JSONBlockCountsStreamModel(models.Model):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        block_counts={
            "text": {
                "min_num": 1
            },
            "rich_text": {
                "max_num": 1
            },
            "image": {
                "min_num": 1,
                "max_num": 1
            },
        },
        use_json_field=True,
    )