Recognise classname parameter on InlinePanel. Fixes #1316

This commit is contained in:
Matt Westcott 2016-09-15 16:44:51 +01:00
parent b4a87d93aa
commit b0aa210078
6 changed files with 15 additions and 9 deletions

View file

@ -18,6 +18,7 @@ Changelog
* Fix: Fixed toggle behaviour of userbar on mobile (Robert Rollins)
* Fix: Image rendition / document file deletion now happens on a post_delete signal, so that files are not lost if the deletion does not proceed (Janneke Janssen)
* Fix: "Your recent edits" list on dashboard no longer leaves out pages that another user has subsequently edited (Michael Cordover, Kees Hink, João Luiz Lorencetti)
* Fix: `InlinePanel` now accepts a `classname` parameter as per the documentation (emg36, Matt Westcott)
1.6.2 (02.09.2016)

View file

@ -166,6 +166,7 @@ Contributors
* Jonathon Moore
* Kees Hink
* Jayden Smith
* emg36
Translators
===========

View file

@ -66,7 +66,7 @@ MultiFieldPanel
InlinePanel
-----------
.. class:: InlinePanel(relation_name, panels=None, classname=None, label='', help_text='', min_num=None, max_num=None)
.. class:: InlinePanel(relation_name, panels=None, classname='', label='', help_text='', min_num=None, max_num=None)
This panel allows for the creation of a "cluster" of related objects over a join to a separate model, such as a list of related links or slides to an image carousel.

View file

@ -53,6 +53,7 @@ Bug fixes
* Fixed toggle behaviour of userbar on mobile (Robert Rollins)
* Image rendition / document file deletion now happens on a post_delete signal, so that files are not lost if the deletion does not proceed (Janneke Janssen)
* "Your recent edits" list on dashboard no longer leaves out pages that another user has subsequently edited (Michael Cordover, Kees Hink, João Luiz Lorencetti)
* ``InlinePanel`` now accepts a ``classname`` parameter as per the documentation (emg36, Matt Westcott)
Upgrade considerations

View file

@ -666,13 +666,14 @@ class BaseInlinePanel(EditHandler):
class InlinePanel(object):
def __init__(self, relation_name, panels=None, label='', help_text='', min_num=None, max_num=None):
def __init__(self, relation_name, panels=None, classname='', label='', help_text='', min_num=None, max_num=None):
self.relation_name = relation_name
self.panels = panels
self.label = label
self.help_text = help_text
self.min_num = min_num
self.max_num = max_num
self.classname = classname
def bind_to_model(self, model):
if django.VERSION >= (1, 9):
@ -690,7 +691,8 @@ class InlinePanel(object):
# TODO: can we pick this out of the foreign key definition as an alternative?
# (with a bit of help from the inlineformset object, as we do for label/heading)
'min_num': self.min_num,
'max_num': self.max_num
'max_num': self.max_num,
'classname': self.classname,
})

View file

@ -671,8 +671,9 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
Check that the inline panel renders the panels set on the model
when no 'panels' parameter is passed in the InlinePanel definition
"""
SpeakerObjectList = ObjectList([InlinePanel('speakers', label="Speakers")]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
SpeakerObjectList = ObjectList([
InlinePanel('speakers', label="Speakers", classname="classname-for-speakers")
]).bind_to_model(EventPage)
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
# SpeakerInlinePanel should instruct the form class to include a 'speakers' formset
@ -681,10 +682,11 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
event_page = EventPage.objects.get(slug='christmas')
form = EventPageForm(instance=event_page)
panel = SpeakerInlinePanel(instance=event_page, form=form)
panel = SpeakerObjectList(instance=event_page, form=form)
result = panel.render_as_field()
self.assertIn('<li class="object classname-for-speakers">', result)
self.assertIn('<label for="id_speakers-0-first_name">Name:</label>', result)
self.assertIn('value="Father"', result)
self.assertIn('<label for="id_speakers-0-last_name">Surname:</label>', result)
@ -699,8 +701,8 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
# rendered panel must contain maintenance form for the formset
self.assertIn('<input id="id_speakers-TOTAL_FORMS" name="speakers-TOTAL_FORMS" type="hidden"', result)
# render_js_init must provide the JS initializer
self.assertIn('var panel = InlinePanel({', panel.render_js_init())
# rendered panel must include the JS initializer
self.assertIn('var panel = InlinePanel({', result)
def test_render_with_panel_overrides(self):
"""
@ -751,5 +753,4 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
def test_invalid_inlinepanel_declaration(self):
with self.ignore_deprecation_warnings():
self.assertRaises(TypeError, lambda: InlinePanel(label="Speakers"))
self.assertRaises(TypeError, lambda: InlinePanel(EventPage, 'speakers', 'bacon', label="Speakers"))
self.assertRaises(TypeError, lambda: InlinePanel(EventPage, 'speakers', label="Speakers", bacon="chunky"))