-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow customising icons for snippets via SnippetViewSet.icon
#10178
Conversation
Manage this branch in SquashTest this branch here: https://laymonagecustom-snippets-icons-mdw1t.squash.io |
78f2ebc
to
1997df4
Compare
da5472f
to
e35670f
Compare
SnippetViewSet.icon
e35670f
to
54ca464
Compare
@@ -1,153 +1,146 @@ | |||
{% extends "wagtailadmin/base.html" %} | |||
{% extends "wagtailadmin/generic/base.html" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this to reduce boilerplate
{% load i18n wagtailadmin_tags %} | ||
|
||
{% block titletag %}{% trans "Workflow progress" %}{% endblock %} | ||
{% block main_content %} | ||
<h2>{% icon object_icon classname="initial" %} {% latest_str object %}</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this page doesn't have any header icon, but there's an icon beside the object's name:
If we add an icon, I feel like it would look a bit weird to have the same icon for both, so I used list-ul
as the header_icon
and came up with object_icon
for the object's icon specifically for this view:
I chose the list-ul
icon because that's what we currently use for the Workflow information dialog:
The SnippetViewSet.icon
will be passed as object_icon
instead of header_icon
.
@@ -106,6 +106,7 @@ def _register_snippet_immediately(model, viewset=None): | |||
) | |||
|
|||
viewsets.register(admin_viewset) | |||
model.snippet_viewset = admin_viewset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit hesitant to add this, but the problem is that the bulk actions view instance is shared across all the snippet models, and it has its own registration mechanism. Thus, the icon needs to be resolved at request time rather than during the view class's instantiation. Adding this allows us to do self.model.snippet_viewset.icon
in get_context_data()
of the view.
I imagine this will be necessary as we add more config options to the ViewSet
anyway. For example, if the base URL path is customisable through the viewset, then we will need a way to access the ViewSet
for a given model. Another way is to create a registry that maps the model to the viewset, but I'm not sure it's worth it...
Or something simpler, we could change the SNIPPET_MODELS
global list into a dictionary that maps each model to the viewset instance? People who rely on get_snippet_models()
will still be able to iterate through it like a list of models, but we will be able to do something like get_snippet_models()[MyModel]
and get the viewset. Still, it's not as handy compared to MyModel.snippet_viewset
, though.
Happy to change the naming, e.g. admin_viewset
or just viewset
. (Though developers might want to have other viewsets that are not SnippetViewSet
for the model as well?)
We can also do this in SnippetViewSet.on_register()
, but we currently patch some other attributes to the model in this function, so I figured I put this here.
SnippetViewSet.icon
SnippetViewSet.icon
…idget() This effectively sets the chooser widget icon to use SnippetViewSet.icon
c2a2e75
to
98dc57c
Compare
98dc57c
to
21f0d98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and works well in my tests!
Merged in 5f154a5 |
Rebase of #9804, fixes #4095, incorporates #10216 as part of #10206.
Unfortunately this does not fix #4040, as it requires overwriting the
SnippetChooserBlock.Meta.icon
attribute at runtime.Hide whitespace when reviewing so that the indentation changes in the templates aren't shown.
Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Define a subclass of
SnippetViewSet
, e.g. with thePerson
model in bakerydemo inwagtail_hooks.py
:Note: when merging, add Daniel Kirkham as co-author of this PR.
Footnotes
Development Testing ↩
Browser and device support ↩
Accessibility Target ↩