Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#502 closed enhancement (fixed)

[patch] added category to feed items

Reported by: eugene@… 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


Per RSS 2.0 Specification ( 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.

---	(revision 640)
+++	(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'], {})
 # This isolates the decision of what the system default is, so calling code can

Attachments (1)

feedgenerator.patch (1.4 KB) - added by eugene@… 13 years ago.

Download all attachments as: .zip

Change History (6)

Changed 13 years ago by eugene@…

Attachment: feedgenerator.patch added


comment:1 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

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 Changed 13 years ago by hugo <gb@…>

Resolution: fixed
Status: closedreopened

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 config ...

comment:3 Changed 13 years ago by eugene@…

What is It is not in Django repository.

comment:4 Changed 13 years ago by hugo <gb@…> is the RSS configuration that is automatically loaded if your settings file is named and you use the standard RSS views

comment:5 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: reopenedclosed

(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

Note: See TracTickets for help on using tickets.
Back to Top