diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8e7d07864d..5b5c76d4ae 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -21,6 +21,7 @@ Changelog * Improved error message on incorrect `{% image %}` tag syntax (LB (Ben Johnston)) * Optimized preview data storage (Bertrand Bordage) * Added `render_landing_page` method to `AbstractForm` to be easily overridden and pass `form_submission` to landing page context (Stein Strindhaug) + * Added `heading` kwarg to `InlinePanel` to allow heading to be set independently of button label (Adrian Turjak) * Fix: Do not remove stopwords when generating slugs from non-ASCII titles, to avoid issues with incorrect word boundaries (Sævar Öfjörð Magnússon) * Fix: The PostgreSQL search backend now preserves ordering of the `QuerySet` when searching with `order_by_relevance=False` (Bertrand Bordage) * Fix: Using `modeladmin_register` as a decorator no longer replaces the decorated class with `None` (Tim Heap) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index f007b7da58..fdba22858d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -262,6 +262,7 @@ Contributors * rifuso * Jon Carmack * Martin Sandström +* Adrian Turjak Translators =========== diff --git a/docs/reference/pages/panels.rst b/docs/reference/pages/panels.rst index 481bb01609..cd87e86ebf 100644 --- a/docs/reference/pages/panels.rst +++ b/docs/reference/pages/panels.rst @@ -66,7 +66,7 @@ MultiFieldPanel InlinePanel ----------- -.. class:: InlinePanel(relation_name, panels=None, classname='', label='', help_text='', min_num=None, max_num=None) +.. class:: InlinePanel(relation_name, panels=None, classname='', heading='', 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. @@ -331,9 +331,9 @@ The ``RelatedLink`` class is a vanilla Django abstract model. The ``BookPageRela .. code-block:: python - InlinePanel( relation_name, panels=None, label='', help_text='', min_num=None, max_num=None ) + InlinePanel( relation_name, panels=None, heading='', label='', help_text='', min_num=None, max_num=None ) -The ``relation_name`` is the ``related_name`` label given to the cluster's ``ParentalKey`` relation. You can add the ``panels`` manually or make them part of the cluster model. ``label`` and ``help_text`` provide a heading and caption, respectively, for the Wagtail editor. Finally, ``min_num`` and ``max_num`` allow you to set the minimum/maximum number of forms that the user must submit. +The ``relation_name`` is the ``related_name`` label given to the cluster's ``ParentalKey`` relation. You can add the ``panels`` manually or make them part of the cluster model. ``heading`` and ``help_text`` provide a heading and caption, respectively, for the Wagtail editor. ``label`` sets the text on the add button, and is used as the heading when ``heading`` is not present. Finally, ``min_num`` and ``max_num`` allow you to set the minimum/maximum number of forms that the user must submit. .. versionchanged:: 1.0 diff --git a/docs/releases/2.0.rst b/docs/releases/2.0.rst index cb9f88487f..a8d1415270 100644 --- a/docs/releases/2.0.rst +++ b/docs/releases/2.0.rst @@ -34,6 +34,7 @@ Other features * Improved error message on incorrect ``{% image %}`` tag syntax (LB (Ben Johnston)) * Optimized preview data storage (Bertrand Bordage) * Added `render_landing_page` method to `AbstractForm` to be easily overridden and pass `form_submission` to landing page context (Stein Strindhaug) + * Added `heading` kwarg to `InlinePanel` to allow heading to be set independently of button label (Adrian Turjak) Bug fixes ~~~~~~~~~ diff --git a/wagtail/admin/edit_handlers.py b/wagtail/admin/edit_handlers.py index dc3dd948ba..cebd9634ca 100644 --- a/wagtail/admin/edit_handlers.py +++ b/wagtail/admin/edit_handlers.py @@ -734,9 +734,10 @@ class BaseInlinePanel(EditHandler): class InlinePanel: - def __init__(self, relation_name, panels=None, classname='', label='', help_text='', min_num=None, max_num=None): + def __init__(self, relation_name, panels=None, classname='', heading='', label='', help_text='', min_num=None, max_num=None): self.relation_name = relation_name self.panels = panels + self.heading = heading or label self.label = label self.help_text = help_text self.min_num = min_num @@ -751,7 +752,8 @@ class InlinePanel: 'relation_name': self.relation_name, 'related': related, 'panels': self.panels, - 'heading': self.label, + 'heading': self.heading, + 'label': self.label, 'help_text': self.help_text, # 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) diff --git a/wagtail/admin/templates/wagtailadmin/edit_handlers/inline_panel.html b/wagtail/admin/templates/wagtailadmin/edit_handlers/inline_panel.html index 8401002f36..aef4eac57c 100644 --- a/wagtail/admin/templates/wagtailadmin/edit_handlers/inline_panel.html +++ b/wagtail/admin/templates/wagtailadmin/edit_handlers/inline_panel.html @@ -25,6 +25,6 @@
diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 21232bdca0..10fe2af149 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -1126,6 +1126,10 @@ class TestPageEdit(TestCase, WagtailTestUtils): response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.event_page.id, ))) self.assertEqual(response.status_code, 200) + # Test InlinePanel labels/headings + self.assertContains(response, '') + self.assertContains(response, 'Add speakers') + def test_edit_multipart(self): """ Test checks if 'enctype="multipart/form-data"' is added and only to forms that require multipart encoding. diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index 028b86ba11..97c14e1484 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -280,7 +280,7 @@ EventPage.content_panels = [ FieldPanel('signup_link'), InlinePanel('carousel_items', label="Carousel items"), FieldPanel('body', classname="full"), - InlinePanel('speakers', label="Speakers"), + InlinePanel('speakers', label="Speakers", heading="Speaker lineup"), InlinePanel('related_links', label="Related links"), FieldPanel('categories'), ]