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)
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 = []
class DefaultRichBlockFieldPage(Page): body = StreamField( [ ("rich_text", RichTextBlock()), ], use_json_field=False, ) content_panels = Page.content_panels + [FieldPanel("body")]
class JSONStreamModel(models.Model): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], use_json_field=True, )
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)
class JSONMinMaxCountStreamModel(models.Model): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], min_num=2, max_num=5, use_json_field=True, )
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())
class CustomRichBlockFieldPage(Page): body = StreamField( [ ("rich_text", RichTextBlock(editor="custom")), ], use_json_field=False, ) content_panels = [ FieldPanel("title", classname="full title"), FieldPanel("body"), ]
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")]
class DefaultStreamPage(Page): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], default="", use_json_field=False, ) content_panels = [ FieldPanel("title"), FieldPanel("body"), ]
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, )