kopia lustrzana https://github.com/wagtail/wagtail
Add new EmailBlock and IntegerBlock
rodzic
35e506c47f
commit
31ce2e802c
|
@ -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)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ Contributors
|
|||
* Johannes Spielmann
|
||||
* Franklin Kingma
|
||||
* Ludolf Takens
|
||||
* Oktay Altay
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
~~~~~~~~
|
||||
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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!")
|
||||
|
|
Ładowanie…
Reference in New Issue