mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge branch 'feature/optional-richtextblocks' of https://github.com/bgrace/wagtail into bgrace-feature/optional-richtextblocks
This commit is contained in:
commit
15a5f7494c
@ -237,10 +237,15 @@ class ChoiceBlock(FieldBlock):
|
||||
|
||||
|
||||
class RichTextBlock(FieldBlock):
|
||||
|
||||
def __init__(self, required=True, help_text=None, **kwargs):
|
||||
self.field_options = {'required': required, 'help_text': help_text}
|
||||
super(RichTextBlock, self).__init__(**kwargs)
|
||||
|
||||
@cached_property
|
||||
def field(self):
|
||||
from wagtail.wagtailcore.fields import RichTextArea
|
||||
return forms.CharField(widget=RichTextArea)
|
||||
return forms.CharField(widget=RichTextArea, **self.field_options)
|
||||
|
||||
def render_basic(self, value):
|
||||
return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
|
||||
|
@ -106,6 +106,23 @@ class TestFieldBlock(unittest.TestCase):
|
||||
self.assertEqual('hello world', value_from_form)
|
||||
|
||||
|
||||
class TestRichTextBlock(unittest.TestCase):
|
||||
|
||||
def test_validate_required_richtext_block(self):
|
||||
block = blocks.RichTextBlock()
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
block.clean('')
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
block.clean(None)
|
||||
|
||||
def test_validate_non_required_richtext_block(self):
|
||||
block = blocks.RichTextBlock(required=False)
|
||||
self.assertEqual(block.clean(''), '')
|
||||
self.assertEqual(block.clean(None), '')
|
||||
|
||||
|
||||
class TestChoiceBlock(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from django.db.models.fields import BLANK_CHOICE_DASH
|
||||
|
Loading…
Reference in New Issue
Block a user