当前位置: 首页>>代码示例>>Python>>正文


Python rich_text.RichText方法代码示例

本文整理汇总了Python中wagtail.core.rich_text.RichText方法的典型用法代码示例。如果您正苦于以下问题:Python rich_text.RichText方法的具体用法?Python rich_text.RichText怎么用?Python rich_text.RichText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.core.rich_text的用法示例。


在下文中一共展示了rich_text.RichText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_legend_display

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_legend_display(self):
        """Verify that the legend appears if set."""
        new_legend = "<h3>ZELDA</h3>"
        self.settings.legend = [('rich_text', RichText(new_legend))]
        self.settings.save()

        response = self.client.get(reverse("schedule_conference"))
        self.assertContains(response, new_legend)
        self.assertNotContains(response, "<p>View past PyData event schedules") 
开发者ID:pydata,项目名称:conf_site,代码行数:11,代码来源:test_schedule_settings.py

示例2: convert_to_streamfield

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def convert_to_streamfield(apps, schema_editor):
    ContentPage = apps.get_model('home', 'ContentPage')
    for page in ContentPage.objects.all():
        # That page.body could be "false-y" yet have a raw_text attribute seems
        # weird; this is an intentional design choice by Wagtail meant to
        # simplify migrations from RichTextField to StreamField.
        if page.body.raw_text and not page.body:
            page.body = [
                ('rich_text', RichText(page.body.raw_text)),
            ]
            page.save() 
开发者ID:freedomofpress,项目名称:securethenews,代码行数:13,代码来源:0008_contentpage_convert_richtextfield_to_streamfield.py

示例3: convert_to_streamfield

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def convert_to_streamfield(apps, schema_editor):
    BlogPost = apps.get_model('blog', 'BlogPost')
    for post in BlogPost.objects.all():
        if post.body.raw_text and not post.body:
            post.body = [
                ('rich_text', RichText(post.body.raw_text)),
            ]
            post.save() 
开发者ID:freedomofpress,项目名称:securethenews,代码行数:10,代码来源:0005_blogpost_convert_richtextfield_to_streamfield.py

示例4: test_render

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_render(self):
        text = '<p>To the <a linktype="page" id="{}">moon</a>!</p>'.format(
            self.single_event_page.id
        )
        value = RichText(text)
        result = str(value)
        expected = (
            '<p>To the <a href="/foo/pointless-suffix/">moon</a>!</p>')
        self.assertEqual(result, expected) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_rich_text.py

示例5: richtext

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def richtext(value):
    if isinstance(value, RichText):
        # passing a RichText value through the |richtext filter should have no effect
        return value
    elif value is None:
        html = ''
    else:
        if isinstance(value, str):
            html = expand_db_html(value)
        else:
            raise TypeError("'richtext' template filter received an invalid value; expected string, got {}.".format(type(value)))
    return render_to_string('wagtailcore/shared/richtext.html', {'html': html}) 
开发者ID:wagtail,项目名称:wagtail,代码行数:14,代码来源:wagtailcore_tags.py

示例6: get_default

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def get_default(self):
        if isinstance(self.meta.default, RichText):
            return self.meta.default
        else:
            return RichText(self.meta.default) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:field_block.py

示例7: to_python

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def to_python(self, value):
        # convert a source-HTML string from the JSONish representation
        # to a RichText object
        return RichText(value) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:field_block.py

示例8: get_prep_value

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def get_prep_value(self, value):
        # convert a RichText object back to a source-HTML string to go into
        # the JSONish representation
        return value.source 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:field_block.py

示例9: test_get_default_with_fallback_value

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_get_default_with_fallback_value(self):
        default_value = blocks.RichTextBlock().get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例10: test_get_default_with_default_none

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_get_default_with_default_none(self):
        default_value = blocks.RichTextBlock(default=None).get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例11: test_get_default_with_empty_string

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_get_default_with_empty_string(self):
        default_value = blocks.RichTextBlock(default='').get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例12: test_get_default_with_nonempty_string

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_get_default_with_nonempty_string(self):
        default_value = blocks.RichTextBlock(default='<p>foo</p>').get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '<p>foo</p>') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例13: test_get_default_with_richtext_value

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_get_default_with_richtext_value(self):
        default_value = blocks.RichTextBlock(default=RichText('<p>foo</p>')).get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '<p>foo</p>') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例14: test_render_form

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_render_form(self):
        """
        render_form should produce the editor-specific rendition of the rich text value
        (which includes e.g. 'data-linktype' attributes on <a> elements)
        """
        block = blocks.RichTextBlock(editor='hallo')
        value = RichText('<p>Merry <a linktype="page" id="4">Christmas</a>!</p>')
        result = block.render_form(value, prefix='richtext')
        self.assertIn(
            (
                '&lt;p&gt;Merry &lt;a data-linktype=&quot;page&quot; data-id=&quot;4&quot;'
                ' data-parent-id=&quot;3&quot; href=&quot;/events/christmas/&quot;&gt;Christmas&lt;/a&gt;!&lt;/p&gt;'
            ),
            result
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:test_blocks.py

示例15: test_validate_required_richtext_block

# 需要导入模块: from wagtail.core import rich_text [as 别名]
# 或者: from wagtail.core.rich_text import RichText [as 别名]
def test_validate_required_richtext_block(self):
        block = blocks.RichTextBlock()

        with self.assertRaises(ValidationError):
            block.clean(RichText('')) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:test_blocks.py


注:本文中的wagtail.core.rich_text.RichText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。