當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。