Added ButtonHelper example code

This commit is contained in:
Kalob Taulien 2019-05-21 11:09:22 -06:00 committed by LB Johnston
parent d76410f5ce
commit 9489cb0758
3 changed files with 41 additions and 1 deletions

View file

@ -10,6 +10,7 @@ Changelog
* Added support for specifying cell alignment on TableBlock (Samuel Mendes)
* Added more informative error when a non-image object is passed to the `image` template tag (Deniz Dogan)
* Added more ARIA landmarks across the admin interface and welcome page for screen reader users to navigate the CMS more easily (Beth Menzies)
* Added ButtonHelper examples in the modelAdmin primer page within documentation (Kalob Taulien)
* Fix: ModelAdmin no longer fails when filtering over a foreign key relation (Jason Dilworth, Matt Westcott)
* Fix: The Wagtail version number is now visible within the Settings menu (Kevin Howbrook)
* Fix: Scaling images now rounds values to an integer so that images render without errors (Adrian Brunyate)

View file

@ -371,7 +371,28 @@ custom class instead of the default, like so:
class MyButtonHelper(ButtonHelper):
...
def add_button(self, classnames_add=None, classnames_exclude=None):
if classnames_add is None:
classnames_add = []
if classnames_exclude is None:
classnames_exclude = []
classnames = self.add_button_classnames + classnames_add
cn = self.finalise_classname(classnames, classnames_exclude)
return {
'url': self.url_helper.create_url,
'label': _('Add %s') % self.verbose_name,
'classname': cn,
'title': _('Add a new %s') % self.verbose_name,
}
def inspect_button(self, pk, classnames_add=None, classnames_exclude=None):
...
def edit_button(self, pk, classnames_add=None, classnames_exclude=None):
...
def delete_button(self, pk, classnames_add=None, classnames_exclude=None):
...
class MyModelAdmin(ModelAdmin):
@ -380,6 +401,23 @@ custom class instead of the default, like so:
modeladmin_register(MyModelAdmin)
To customise the buttons found in the ModelAdmin List View you can change the
returned dictionary in the ``add_button``, ``delete_button``, ``edit_button``
or ``inspect_button`` methods. For example if you wanted to change the ``Delete``
button you could modify the ``delete_button`` method in your ``ButtonHelper`` like so:
.. code-block:: python
class MyButtonHelper(ButtonHelper):
...
def delete_button(self, pk, classnames_add=None, classnames_exclude=None):
...
return {
'url': reverse("your_custom_url"),
'label': _('Delete'),
'classname': "custom-css-class",
'title': _('Delete this item')
}
Or, if you have a more complicated use case, where simply setting an attribute
isn't possible or doesn't meet your needs, you can override the

View file

@ -19,6 +19,7 @@ Other features
* Added support for specifying cell alignment on TableBlock (Samuel Mendes)
* Added more informative error when a non-image object is passed to the ``image`` template tag (Deniz Dogan)
* Added more ARIA landmarks across the admin interface and welcome page for screen reader users to navigate the CMS more easily (Beth Menzies)
* Added ButtonHelper examples in the modelAdmin primer page within documentation (Kalob Taulien)
Bug fixes
~~~~~~~~~