diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0fe4e733e..409f8506c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -13,12 +13,14 @@ Changelog * The 'choices' field on the form builder no longer has a maximum length (Johannes Spielmann) * The wagtailimages.Filter model has been removed, and converted to a Python class instead (Gagaro) * Multiple ChooserBlocks inside a StreamField are now prefetched in bulk, for improved performance (Michael van Tellingen, Roel Bruggink, Matt Westcott) + * Add new EmailBlock and IntegerBlock (Oktay Altay) * Fix: Email templates and document uploader now support custom `STATICFILES_STORAGE` (Jonny Scholes) * Fix: Removed alignment options (deprecated in HTML and not rendered by Wagtail) from `TableBlock` context menu (Moritz Pfeiffer) * Fix: Fixed incorrect CSS path on ModelAdmin's "choose a parent page" view * Fix: Prevent empty redirect by overnormalisation (Franklin Kingma, Ludolf Takens) * Fix: "Remove link" button in rich text editor didn't trigger "edit" event, leading to the change to sometimes not be persisted (Matt Westcott) + 1.5.2 (08.06.2016) ~~~~~~~~~~~~~~~~~~ diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index b02297151..0b2c4477d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -145,6 +145,7 @@ Contributors * Johannes Spielmann * Franklin Kingma * Ludolf Takens +* Oktay Altay Translators =========== diff --git a/docs/releases/1.6.rst b/docs/releases/1.6.rst index dbe82aa80..9934e055e 100644 --- a/docs/releases/1.6.rst +++ b/docs/releases/1.6.rst @@ -23,6 +23,7 @@ Minor features * The 'choices' field on the form builder no longer has a maximum length (Johannes Spielmann) * The wagtailimages.Filter model has been removed, and converted to a Python class instead (Gagaro) * Multiple ChooserBlocks inside a StreamField are now prefetched in bulk, for improved performance (Michael van Tellingen, Roel Bruggink, Matt Westcott) + * Added new EmailBlock and IntegerBlock (Oktay Altay) Bug fixes diff --git a/docs/topics/streamfield.rst b/docs/topics/streamfield.rst index 497453031..c56b9160d 100644 --- a/docs/topics/streamfield.rst +++ b/docs/topics/streamfield.rst @@ -89,6 +89,21 @@ TextBlock A multi-line text input. As with ``CharBlock``, the keyword arguments ``required``, ``max_length``, ``min_length`` and ``help_text`` are accepted. + +EmailBlock +~~~~~~~~~~ + +``wagtail.wagtailcore.blocks.EmailBlock`` + +A single-line email input that validates that the email is a valid Email Address. The keyword arguments ``required`` and ``help_text`` are accepted. + +IntegerBlock +~~~~~~~~~~~~ + +``wagtail.wagtailcore.blocks.IntegerBlock`` + +A single-line integer input that validates that the integer is a valid whole number. The keyword arguments ``required``, ``max_length``, ``min_length`` and ``help_text`` are accepted. + URLBlock ~~~~~~~~ diff --git a/wagtail/wagtailcore/blocks/field_block.py b/wagtail/wagtailcore/blocks/field_block.py index 14c4bf6a6..00eb5c437 100644 --- a/wagtail/wagtailcore/blocks/field_block.py +++ b/wagtail/wagtailcore/blocks/field_block.py @@ -230,6 +230,34 @@ class DateTimeBlock(FieldBlock): icon = "date" +class EmailBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): + self.field = forms.EmailField( + required=required, + help_text=help_text, + ) + super(EmailBlock, self).__init__(**kwargs) + + class Meta: + icon = "mail" + + +class IntegerBlock(FieldBlock): + + def __init__(self, required=True, help_text=None, min_value=None, + max_value=None, **kwargs): + self.field = forms.IntegerField( + required=required, + help_text=help_text, + min_value=min_value, + max_value=max_value + ) + super(IntegerBlock, self).__init__(**kwargs) + + class Meta: + icon = "plus-inverse" + + class ChoiceBlock(FieldBlock): choices = () @@ -475,7 +503,7 @@ class PageChooserBlock(ChooserBlock): # rather than wagtailcore.blocks.field.FooBlock block_classes = [ FieldBlock, CharBlock, URLBlock, RichTextBlock, RawHTMLBlock, ChooserBlock, PageChooserBlock, - TextBlock, BooleanBlock, DateBlock, TimeBlock, DateTimeBlock, ChoiceBlock, + TextBlock, BooleanBlock, DateBlock, TimeBlock, DateTimeBlock, ChoiceBlock, EmailBlock, IntegerBlock, ] DECONSTRUCT_ALIASES = { cls: 'wagtail.wagtailcore.blocks.%s' % cls.__name__ diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 1e9aabe6b..b46f85587 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -29,6 +29,54 @@ class FooStreamBlock(blocks.StreamBlock): class TestFieldBlock(unittest.TestCase): + def test_integerfield_type(self): + block = blocks.IntegerBlock() + digit = block.value_from_form(1234) + + self.assertEqual(type(digit), int) + + def test_integerfield_render(self): + block = blocks.IntegerBlock() + digit = block.value_from_form(1234) + + self.assertEqual(digit, 1234) + + def test_integerfield_render_required_error(self): + block = blocks.IntegerBlock() + + with self.assertRaises(ValidationError): + block.clean("") + + def test_integerfield_render_max_value_validation(self): + block = blocks.IntegerBlock(max_value=20) + + with self.assertRaises(ValidationError): + block.clean(25) + + def test_integerfield_render_min_value_validation(self): + block = blocks.IntegerBlock(min_value=20) + + with self.assertRaises(ValidationError): + block.clean(10) + + def test_emailfield_render(self): + block = blocks.EmailBlock() + email = block.render("example@email.com") + + self.assertEqual(email, "example@email.com") + + def test_emailfield_render_required_error(self): + block = blocks.EmailBlock() + + with self.assertRaises(ValidationError): + block.clean("") + + def test_emailfield_format_validation(self): + block = blocks.EmailBlock() + + with self.assertRaises(ValidationError): + block.clean("example.email.com") + def test_charfield_render(self): block = blocks.CharBlock() html = block.render("Hello world!")