-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Fixed #35886 -- Moved object-based Script media assets to the public API #18782
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
Conversation
31524e7
to
3d1e8bf
Compare
d25fa62
to
2e8c52c
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.
Thanks for working on this, this looks very good.
I think adding a test which adds a data attribute to a JS
instance would be nice. The current API doesn't allow attributes with dashes since it uses **kwargs
to pass attributes though, so that's not possible. I'm using a dictionary as a second argument instead of the **kwargs
in django-js-asset so that things like this are possible:
js=[
"admin/js/jquery.init.js",
"admin_ordering/jquery-ui.min.js",
JS(
"admin_ordering/admin_ordering.js",
{
"class": "admin-ordering-context",
"data-context": json.dumps(context),
},
),
],
I think that's a useful thing and it would be nice if the new JS
object would support something like this as well. I wrote a blog post a few years back why I did it this way:
https://406.ch/writing/django-admin-apps-and-content-security-policy-compliance/
633f030
to
19b35b2
Compare
Thanks, @matthiask, I truly appreciate that you took the time to review this. I am also happy to see that many people care out this. Let's address some of your points in writing: I wouldn't want to pass a dictionary to a method, to any method, really. As dictionaries are mutable in Python, it's more common to unpack and shallow copy them. That being said, your use case is easily solvable, like so: CSS("path/to/file", **{"async": True, "date-foo": "bar"}) The only difference being I will extend the documentation to accommodate more use cases. |
Ah yes, I always forget this is possible! |
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.
Love it! I left some minor notes.
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.
Thank you @codingjoe 👍 I have a couple of suggestions
Thank y'all for your review. Much appreciated 🙏 |
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.
👍 👍
c2c5f69
to
51212dd
Compare
5c63aff
to
568d25e
Compare
11fdab9
to
4c84acd
Compare
861243a
to
32d3180
Compare
ae5a7ed
to
39ae25f
Compare
39ae25f
to
e2d19b2
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.
Thank you for your work and patience on this @codingjoe ⭐ this looks good to me.
I'm going on holiday and won't merge this till the new year 🎄
That also gives folks the opportunity to shout if they spot something 👀
Thank you so much for your support @sarahboyce. What a wonderful Christmas gift. I hope you have a jolly good holiday yourself 🎄✨☃️ |
e2d19b2
to
18397c4
Compare
18397c4
to
cd35cbc
Compare
Trac ticket number
ticket-35886
Branch description
This is a successor to ticket-29490 and a result of the discussion on ticket-22298 and its corresponding forum thread.
This ticket aims to move object-based media assets to the public API and documentation.
A sample implementation has been part of the test suite for years, see also:
django/tests/forms_tests/tests/test_media.py
Lines 717 to 771 in 97a6a67
The goal is to support form assets with modern attributes, like:
And other standardized attributes, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
The same can be done for stylesheets via the link tag, which does support many more attributes than media, see also: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
Checklist
main
branch.I have attached screenshots in both light and dark modes for any UI changes.Considerations & Scope
Defining CSS in dictionaries is moderately awkward with the new objects. It could be considered to move to a flat list going forward. However, this should be done in separate ticket.