Support field widget media inside streamfield blocks

pull/2473/merge
Karl Hobley 2016-04-04 18:48:55 +01:00 zatwierdzone przez Mikalai Radchuk
rodzic 948bdf8d3c
commit fcd2aa023c
4 zmienionych plików z 31 dodań i 0 usunięć

Wyświetl plik

@ -28,6 +28,7 @@ Changelog
* The multiple image uploader now displays details of server errors (Nigel Fletton)
* Added `WAGTAIL_APPEND_SLASH` setting to determine whether page URLs end in a trailing slash (Andrew Tork Baker)
* Added auto resizing text field, richtext field, and snippet chooser to styleguide (Liam Brenner)
* Support field widget media inside `StreamBlock` blocks (Karl Hobley)
* Fix: The currently selected day is now highlighted only in the correct month in date pickers (Jonas Lergell)
* Fix: Fixed crash when an image without a source file was resized with the "dynamic serve view"
* Fix: Registered settings admin menu items now show active correctly (Matthew Downey)

Wyświetl plik

@ -53,6 +53,7 @@ Minor features
* The multiple image uploader now displays details of server errors (Nigel Fletton)
* Added ``WAGTAIL_APPEND_SLASH`` setting to determine whether page URLs end in a trailing slash - see :ref:`append_slash` (Andrew Tork Baker)
* Added auto resizing text field, richtext field, and snippet chooser to styleguide (Liam Brenner)
* Support field widget media inside ``StreamBlock`` blocks (Karl Hobley)
Bug fixes
~~~~~~~~~

Wyświetl plik

@ -74,6 +74,10 @@ class FieldBlock(Block):
# the one this block works with natively
return self.value_from_form(self.field.clean(self.value_for_form(value)))
@property
def media(self):
return self.field.widget.media
class Meta:
# No icon specified here, because that depends on the purpose that the
# block is being used for. Feel encouraged to specify an icon in your

Wyświetl plik

@ -120,6 +120,31 @@ class TestFieldBlock(unittest.TestCase):
value_from_form = block.value_from_datadict({'title': 'hello world'}, {}, 'title')
self.assertEqual('hello world', value_from_form)
def test_widget_media(self):
class CalendarWidget(forms.TextInput):
@property
def media(self):
return forms.Media(
css={'all': ('pretty.css',)},
js=('animations.js', 'actions.js')
)
class CalenderBlock(blocks.FieldBlock):
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs):
# Set widget to CalenderWidget
self.field = forms.CharField(
required=required,
help_text=help_text,
max_length=max_length,
min_length=min_length,
widget=CalendarWidget(),
)
super(blocks.FieldBlock, self).__init__(**kwargs)
block = CalenderBlock()
self.assertIn('pretty.css', ''.join(block.all_media().render_css()))
self.assertIn('animations.js', ''.join(block.all_media().render_js()))
class TestRichTextBlock(TestCase):
fixtures = ['test.json']