Django

Code

Ticket #502 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

[patch] added category to feed items

Reported by: eugene@lazutkin.com Assigned to: adrian
Milestone: Component: RSS framework
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

feedgenerator.patch (1.4 kB) - added by eugene@lazutkin.com on 09/14/05 01:44:18.
patch

Change History

09/14/05 01:44:18 changed by eugene@lazutkin.com

  • attachment feedgenerator.patch added.

patch

09/14/05 12:40:37 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [641], but I used "categories", which is required to be a list, instead of "category," for the sake of being explicit.

09/15/05 09:01:11 changed by hugo <gb@bofh.ms>

  • status changed from closed to reopened.
  • resolution deleted.

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

09/15/05 12:00:22 changed by eugene@lazutkin.com

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

09/15/05 12:22:04 changed by hugo <gb@bofh.ms>

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

11/11/05 21:44:55 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

(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/Change #502 ([patch] added category to feed items)




Change Properties
Action