0
0
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:
Matt Westcott 2015-05-30 11:17:16 +01:00
commit 15a5f7494c
2 changed files with 23 additions and 1 deletions

View File

@ -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>')

View File

@ -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