Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SVG icons in ModelAdmin menu items #6402

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog
* Specify minimum Python version in setup.py (Vince Salvino)
* Show user's full name in report views (Matt Westcott)
* Improve Wagtail admin page load performance by caching SVG icons sprite in localstorage (Coen van der Kamp)
* Support SVG icons in ModelAdmin menu items (Scott Cranfill)
* Fix: Make page-level actions accessible to keyboard users in page listing tables (Jesse Menn)
* Fix: `WAGTAILFRONTENDCACHE_LANGUAGES` was being interpreted incorrectly. It now accepts a list of strings, as documented (Karl Hobley)
* Fix: Update oEmbed endpoints to use https where available (Matt Westcott)
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/contrib/modeladmin/menu_item.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ page-type models, and ``'snippet'`` for others.
If you're using a ``ModelAdminGroup`` class to group together several
``ModelAdmin`` classes in their own sub-menu, and want to change the menu item
used to represent the group, you should override the ``menu_icon`` attribute on
your ``ModelAdminGroup`` class (``'icon-folder-open-inverse'`` is the default).
your ``ModelAdminGroup`` class (``'folder-open-inverse'`` is the default).

.. _modeladmin_menu_order:

Expand Down
1 change: 1 addition & 0 deletions docs/releases/2.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Other features
* Add support for hierarchical/nested Collections (Robert Rollins)
* Show user's full name in report views (Matt Westcott)
* Improve Wagtail admin page load performance by caching SVG icons sprite in localstorage (Coen van der Kamp)
* Support SVG icons in ModelAdmin menu items (Scott Cranfill)


Bug fixes
Expand Down
20 changes: 16 additions & 4 deletions wagtail/contrib/modeladmin/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ class ModelAdminMenuItem(MenuItem):
def __init__(self, model_admin, order):
self.model_admin = model_admin
url = model_admin.url_helper.index_url
classnames = 'icon icon-%s' % model_admin.get_menu_icon()
menu_icon = model_admin.get_menu_icon()
if menu_icon[:3] == 'fa-':
classnames = 'icon icon-%s' % menu_icon
icon_name = None
else:
classnames = ''
icon_name = menu_icon
super().__init__(
label=model_admin.get_menu_label(), url=url,
classnames=classnames, order=order)
classnames=classnames, icon_name=icon_name, order=order)

def is_shown(self, request):
return self.model_admin.permission_helper.user_can_list(request.user)
Expand All @@ -25,10 +31,16 @@ class GroupMenuItem(SubmenuMenuItem):
pages
"""
def __init__(self, modeladmingroup, order, menu):
classnames = 'icon icon-%s' % modeladmingroup.get_menu_icon()
menu_icon = modeladmingroup.get_menu_icon()
if menu_icon[:3] == 'fa-':
classnames = 'icon icon-%s' % menu_icon
icon_name = None
else:
classnames = ''
icon_name = menu_icon
super().__init__(
label=modeladmingroup.get_menu_label(), menu=menu,
classnames=classnames, order=order, )
classnames=classnames, icon_name=icon_name, order=order, )

def is_shown(self, request):
"""
Expand Down
2 changes: 1 addition & 1 deletion wagtail/contrib/modeladmin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def get_app_label_from_subitems(self):
return ''

def get_menu_icon(self):
return self.menu_icon or 'icon-folder-open-inverse'
return self.menu_icon or 'folder-open-inverse'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: will need a corresponding doc update (cosmetic).


def get_menu_order(self):
return self.menu_order or 999
Expand Down