Python wagtail.core.blocks.RawHTMLBlock() Examples

The following are 12 code examples of wagtail.core.blocks.RawHTMLBlock(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wagtail.core.blocks , or try the search function .
Example #1
Source File: compare.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_comparison_class_for_block(block):
    if hasattr(block, 'get_comparison_class'):
        return block.get_comparison_class()
    elif isinstance(block, (blocks.CharBlock, blocks.TextBlock)):
        return CharBlockComparison
    elif isinstance(block, blocks.RawHTMLBlock):
        # Compare raw HTML blocks as if they were plain text, so that tags are shown explicitly
        return CharBlockComparison
    elif isinstance(block, blocks.RichTextBlock):
        return RichTextBlockComparison
    elif isinstance(block, blocks.StructBlock):
        return StructBlockComparison
    else:
        # As all stream field blocks have a HTML representation, fall back to diffing that.
        return RichTextBlockComparison 
Example #2
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_default_with_fallback_value(self):
        default_value = blocks.RawHTMLBlock().get_default()
        self.assertEqual(default_value, '')
        self.assertIsInstance(default_value, SafeData) 
Example #3
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_default_with_none(self):
        default_value = blocks.RawHTMLBlock(default=None).get_default()
        self.assertEqual(default_value, '')
        self.assertIsInstance(default_value, SafeData) 
Example #4
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_default_with_empty_string(self):
        default_value = blocks.RawHTMLBlock(default='').get_default()
        self.assertEqual(default_value, '')
        self.assertIsInstance(default_value, SafeData) 
Example #5
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_default_with_nonempty_string(self):
        default_value = blocks.RawHTMLBlock(default='<blink>BÖÖM</blink>').get_default()
        self.assertEqual(default_value, '<blink>BÖÖM</blink>')
        self.assertIsInstance(default_value, SafeData) 
Example #6
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_deserialize(self):
        block = blocks.RawHTMLBlock()
        result = block.to_python('<blink>BÖÖM</blink>')
        self.assertEqual(result, '<blink>BÖÖM</blink>')
        self.assertIsInstance(result, SafeData) 
Example #7
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_render(self):
        block = blocks.RawHTMLBlock()
        result = block.render(mark_safe('<blink>BÖÖM</blink>'))
        self.assertEqual(result, '<blink>BÖÖM</blink>')
        self.assertIsInstance(result, SafeData) 
Example #8
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_render_form(self):
        block = blocks.RawHTMLBlock()
        result = block.render_form(mark_safe('<blink>BÖÖM</blink>'), prefix='rawhtml')
        self.assertIn('<textarea ', result)
        self.assertIn('name="rawhtml"', result)
        self.assertIn('&lt;blink&gt;BÖÖM&lt;/blink&gt;', result) 
Example #9
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_form_response(self):
        block = blocks.RawHTMLBlock()
        result = block.value_from_datadict({'rawhtml': '<blink>BÖÖM</blink>'}, {}, prefix='rawhtml')
        self.assertEqual(result, '<blink>BÖÖM</blink>')
        self.assertIsInstance(result, SafeData) 
Example #10
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_value_omitted_from_data(self):
        block = blocks.RawHTMLBlock()
        self.assertFalse(block.value_omitted_from_data({'rawhtml': 'ohai'}, {}, 'rawhtml'))
        self.assertFalse(block.value_omitted_from_data({'rawhtml': ''}, {}, 'rawhtml'))
        self.assertTrue(block.value_omitted_from_data({'nothing-here': 'nope'}, {}, 'rawhtml')) 
Example #11
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_clean_nonrequired_field(self):
        block = blocks.RawHTMLBlock(required=False)
        result = block.clean(mark_safe('<blink>BÖÖM</blink>'))
        self.assertEqual(result, '<blink>BÖÖM</blink>')
        self.assertIsInstance(result, SafeData)

        result = block.clean(mark_safe(''))
        self.assertEqual(result, '')
        self.assertIsInstance(result, SafeData) 
Example #12
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_render_with_validator(self):
        def validate_contains_foo(value):
            if 'foo' not in value:
                raise ValidationError("Value must contain 'foo'")

        block = blocks.RawHTMLBlock(validators=[validate_contains_foo])

        with self.assertRaises(ValidationError):
            block.clean(mark_safe('<p>bar</p>'))