0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 09:33:54 +01:00

implement help_text on chooser blocks

This commit is contained in:
Matt Westcott 2015-06-05 22:15:19 +01:00
parent 3afe8f4f71
commit f55b7210ca
2 changed files with 7 additions and 3 deletions

View File

@ -306,14 +306,17 @@ class RawHTMLBlock(FieldBlock):
class ChooserBlock(FieldBlock):
def __init__(self, required=True, **kwargs):
def __init__(self, required=True, help_text=None, **kwargs):
self.required = required
self.help_text = help_text
super(ChooserBlock, self).__init__(**kwargs)
"""Abstract superclass for fields that implement a chooser interface (page, image, snippet etc)"""
@cached_property
def field(self):
return forms.ModelChoiceField(queryset=self.target_model.objects.all(), widget=self.widget, required=self.required)
return forms.ModelChoiceField(
queryset=self.target_model.objects.all(), widget=self.widget, required=self.required,
help_text=self.help_text)
def to_python(self, value):
# the incoming serialised value should be None or an ID

View File

@ -1218,7 +1218,7 @@ class TestPageChooserBlock(TestCase):
self.assertEqual(block.to_python(None), None)
def test_form_render(self):
block = blocks.PageChooserBlock()
block = blocks.PageChooserBlock(help_text="pick a page, any page")
empty_form_html = block.render_form(None, 'page')
self.assertIn('<input id="page" name="page" placeholder="" type="hidden" />', empty_form_html)
@ -1227,6 +1227,7 @@ class TestPageChooserBlock(TestCase):
christmas_form_html = block.render_form(christmas_page, 'page')
expected_html = '<input id="page" name="page" placeholder="" type="hidden" value="%d" />' % christmas_page.id
self.assertIn(expected_html, christmas_form_html)
self.assertIn("pick a page, any page", christmas_form_html)
def test_form_response(self):
block = blocks.PageChooserBlock()