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
Fixed #12978 -- Added support for RSS feed stylesheets. #18120
base: main
Are you sure you want to change the base?
Fixed #12978 -- Added support for RSS feed stylesheets. #18120
Conversation
accd5e1
to
06bd3c7
Compare
e258b5e
to
4236ef0
Compare
Nice to see this request popping up again after 14 years 😂 https://code.djangoproject.com/ticket/12978 |
docs/ref/contrib/syndication.txt
Outdated
from django.contrib.syndication.views import Feed | ||
from django.urls import reverse | ||
|
||
|
||
class FeedWithStylesheetView(Feed): | ||
... # author, etc. | ||
xsl_stylesheet_url = reverse("your-custom-view-name") |
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.
Oh, I didn't realize there was already a ticket for this (I did search before creating one but clearly not well enough). Do you think those are reasonable limitations @yuvadm ? Your proposal was for multiple RSS stylesheets but from the little I've seen, XSL seems like a more widespread format, do you agree? |
@bmispelon after so much time, I hardly remember why I added support for multiple stylesheets, I was probably aiming for maximum flexibility. If I were to re-implemented, in terms of API design, I'd probably be liberal in accepting both single and iterable stylesheets in one arg, but unsure if that meets Django code standards. Anyway nice to see great minds thinking alike 😄 |
Hey @bmispelon, I don't mean to rush you but wanted to mention that when this is ready for a review, please update the ticket flags in trac so it shows in the review queue. Thanks! |
c4de8d5
to
66e1eac
Compare
Thanks for the heads up, I hadn't notice that the original ticket still had the "patch needs improvement" flag. I've squashed and rebased this PR and updated the flags on the ticket, it should be ready to review. |
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.
Very thorough PR, looks generally good to me, although I'm not familiar with XSLT stylesheets.
I think a css stylesheet should also be supported 🤔 |
66e1eac
to
8ecba20
Compare
I'm a bit puzzled about the test failure. The failing test passes for me locally 🤔 |
django/contrib/syndication/views.py
Outdated
@@ -160,6 +160,7 @@ def get_feed(self, obj, request): | |||
feed_copyright=self._get_dynamic_attr("feed_copyright", obj), | |||
feed_guid=self._get_dynamic_attr("feed_guid", obj), | |||
ttl=self._get_dynamic_attr("ttl", obj), | |||
stylesheet=self._get_dynamic_attr("stylesheet", obj), |
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.
Do we want to support having multiple stylesheets?
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.
I wanted to keep the API simple because I assume most people only really have a single stylesheet. I pushed a separate commit that adds documentation (and tests) for how to extend the Feed
class to support multiple stylesheets.
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 👍 that's a lovely addition
This is what I'm thinking.
If we think we might support multiple in the future, we'd want to deprecate stylesheet
and add stylesheets
. In that case it's easier to do now.
Otherwise, as you have documented how to do this in your own code, we'd be recommending users that it should be in your own code and that's a decision to not add it into Django.
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.
I've added support for multiple stylesheets (I tried to contain it to a single commit so you can see the diff easier), it didn't add much complexity and your argument about future-proofing against a possible deprecation cycle is convincing.
I did opt to support both a single stylesheet and a list of them, which does make the code (and the documentation) a bit more complex, but I thought it was worth it so that we can offer a simpler API when people only want to use a single stylesheet. If you think that tradeoff is not worth it, I'm also happy to make the API list-only.
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.
I don't have too strong of an opinion here. I personally would have just supported lists/tuples (a bit like admin inlines) but I don't mind having this. We can get another opinion 👍
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.
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.
With the name stylesheets
I'd expect to pass an iterable, as a user my immediate reaction is to do stylesheets=["style.css"]
. From the defensive programming side, I'd silently accept a single string as well.
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.
I'd agree with @yuvadm here :) Thanks so much for working on this PR!
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.
The version I've pushed now supports only list/tuples and throws a TypeError
if you pass something else (str
or Stylesheet
). While I can see the argument for trying to be as lenient as possible in terms of what is accepted, I couldn't find examples in the Django codebase that did that, and I'm hesitant to have an undocumented API.
With this approach I figured it's easier to make the function more flexible if we feel the need for it in the future (since we won't have to go through a deprecation period).
Do you think that's acceptable?
855b5f2
to
a5ecf0f
Compare
django/contrib/syndication/views.py
Outdated
@@ -160,6 +160,7 @@ def get_feed(self, obj, request): | |||
feed_copyright=self._get_dynamic_attr("feed_copyright", obj), | |||
feed_guid=self._get_dynamic_attr("feed_guid", obj), | |||
ttl=self._get_dynamic_attr("ttl", obj), | |||
stylesheet=self._get_dynamic_attr("stylesheet", obj), |
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 👍 that's a lovely addition
This is what I'm thinking.
If we think we might support multiple in the future, we'd want to deprecate stylesheet
and add stylesheets
. In that case it's easier to do now.
Otherwise, as you have documented how to do this in your own code, we'd be recommending users that it should be in your own code and that's a decision to not add it into Django.
647fb20
to
4426a29
Compare
4426a29
to
96a77c2
Compare
django/contrib/syndication/views.py
Outdated
@@ -160,6 +160,7 @@ def get_feed(self, obj, request): | |||
feed_copyright=self._get_dynamic_attr("feed_copyright", obj), | |||
feed_guid=self._get_dynamic_attr("feed_guid", obj), | |||
ttl=self._get_dynamic_attr("ttl", obj), | |||
stylesheet=self._get_dynamic_attr("stylesheet", obj), |
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.
I don't have too strong of an opinion here. I personally would have just supported lists/tuples (a bit like admin inlines) but I don't mind having this. We can get another opinion 👍
80b927c
to
a32185d
Compare
a32185d
to
923cb21
Compare
Trac ticket number
ticket-35420 (duplicate)
ticket-12978 (the actual original ticket)
Branch description
To simplify the implementation I decided to restrict the types of stylesheets to XSL (it lets me hardcode the type of the stylesheet), it seems to be the de-facto standard anyway.
Checklist
main
branch.