#502 closed enhancement (fixed)
[patch] added category to feed items
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.syndication | Version: | |
Severity: | trivial | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Per RSS 2.0 Specification (http://blogs.law.harvard.edu/tech/rss) I've added categories to post items.
SyndicationFeed.add_item() can accept kw-parameter 'category', which can be a unicode string or a list of unicode strings. Rss201rev2Feed uses it to generate one or multiple <category> tags per item.
Index: feedgenerator.py =================================================================== --- feedgenerator.py (revision 640) +++ feedgenerator.py (working copy) @@ -33,7 +33,7 @@ def add_item(self, title, link, description, author_email=None, author_name=None, pubdate=None, comments=None, unique_id=None, - enclosure=None): + enclosure=None, category=None): """ Adds an item to the feed. All args are expected to be Python Unicode objects except pubdate, which is a datetime.datetime object, and @@ -49,6 +49,7 @@ 'comments': comments, 'unique_id': unique_id, 'enclosure': enclosure, + 'category': category, }) def num_items(self): @@ -142,6 +143,12 @@ handler.addQuickElement(u"enclosure", '', {u"url": item['enclosure'].url, u"length": item['enclosure'].length, u"type": item['enclosure'].mime_type}) + if item['category'] is not None: + if isinstance(item['category'], list): + for cat in item['category']: + handler.addQuickElement(u"category", cat, {}) + else: + handler.addQuickElement(u"category", item['category'], {}) handler.endElement(u"item") # This isolates the decision of what the system default is, so calling code can
Attachments (1)
Change History (6)
by , 19 years ago
Attachment: | feedgenerator.patch added |
---|
comment:1 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in [641], but I used "categories", which is required to be a list, instead of "category," for the sake of being explicit.
comment:2 by , 19 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I think this would need a callback in the FeedConfiguration to be really usefull - with the current state the generator does support categories, but one can't make use of it in the main_rss.py config ...
comment:4 by , 19 years ago
main_rss.py is the RSS configuration that is automatically loaded if your settings file is named main.py and you use the standard RSS views
comment:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [1194]) Completely refactored legacy RSS framework to the new django.contrib.syndication package. Also added Atom support, changed the way feeds are registered and added documentation for the whole lot. This is backwards-incompatible, but the RSS framework had not yet been documented, so this should only affect tinkerers and WorldOnline. Fixes #329, #498, #502 and #554. Thanks for various patches/ideas to alastair, ismael, hugo, eric moritz and garthk
patch