Code

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#502 closed enhancement (fixed)

[patch] added category to feed items

Reported by: eugene@… Owned by: adrian
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: UI/UX:

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)

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

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by eugene@…

patch

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to 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 Changed 9 years ago by hugo <gb@…>

  • Resolution fixed deleted
  • Status changed from closed to 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:3 Changed 9 years ago by eugene@…

What is main_rss.py? It is not in Django repository.

comment:4 Changed 9 years ago by hugo <gb@…>

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 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.