Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1473 -- Added support for categories back into syndication feeds

(was accidently removed in r1994). Thanks, k.shaposhnikov@gmail.com


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3143 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a93b1f7ac34c61ae4aa64423e9e46dc5d5349434 1 parent c0ea328
Malcolm Tredinnick authored June 19, 2006
2  django/contrib/syndication/feeds.py
@@ -73,6 +73,7 @@ def get_feed(self, url=None):
73 73
             author_name = self.__get_dynamic_attr('author_name', obj),
74 74
             author_link = self.__get_dynamic_attr('author_link', obj),
75 75
             author_email = self.__get_dynamic_attr('author_email', obj),
  76
+            categories = self.__get_dynamic_attr('categories', obj),
76 77
         )
77 78
 
78 79
         try:
@@ -110,5 +111,6 @@ def get_feed(self, url=None):
110 111
                 author_name = author_name,
111 112
                 author_email = author_email,
112 113
                 author_link = author_link,
  114
+                categories = self.__get_dynamic_attr('item_categories', item),
113 115
             )
114 116
         return feed
2  django/utils/feedgenerator.py
@@ -126,6 +126,8 @@ def write(self, outfile, encoding):
126 126
         handler.addQuickElement(u"description", self.feed['description'])
127 127
         if self.feed['language'] is not None:
128 128
             handler.addQuickElement(u"language", self.feed['language'])
  129
+        for cat in self.feed['categories']:
  130
+            handler.addQuickElement(u"category", cat)
129 131
         self.write_items(handler)
130 132
         self.endChannelElement(handler)
131 133
         handler.endElement(u"rss")
36  docs/syndication_feeds.txt
@@ -439,6 +439,23 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
439 439
 
440 440
         author_link = 'http://www.example.com/' # Hard-coded author URL.
441 441
 
  442
+        # CATEGORIES -- One of the following three is optional. The framework
  443
+        # looks for them in this order. In each case, the method/attribute
  444
+        # should return an iterable object that returns strings.
  445
+
  446
+        def categories(self, obj):
  447
+            """
  448
+            Takes the object returned by get_object() and returns the feed's
  449
+            categories as iterable over strings.
  450
+            """
  451
+
  452
+        def categories(self):
  453
+            """
  454
+            Returns the feed's categories as iterable over strings.
  455
+            """
  456
+
  457
+        categories = ("python", "django") # Hard-coded list of categories.
  458
+
442 459
         # ITEMS -- One of the following three is required. The framework looks
443 460
         # for them in this order.
444 461
 
@@ -602,6 +619,25 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
602 619
 
603 620
         item_pubdate = datetime.datetime(2005, 5, 3) # Hard-coded pubdate.
604 621
 
  622
+        # ITEM CATEGORIES -- It's optional to use one of these three. This is
  623
+        # a hook that specifies how to get the list of categories for a given
  624
+        # item. In each case, the method/attribute should return an iterable
  625
+        # object that returns strings.
  626
+
  627
+        def item_categories(self, item):
  628
+            """
  629
+            Takes an item, as returned by items(), and returns the item's
  630
+            categories.
  631
+            """
  632
+
  633
+        def item_categories(self):
  634
+            """
  635
+            Returns the categories for every item in the feed.
  636
+            """
  637
+
  638
+        item_categories = ("python", "django") # Hard-coded categories.
  639
+
  640
+
605 641
 The low-level framework
606 642
 =======================
607 643
 

0 notes on commit a93b1f7

Please sign in to comment.
Something went wrong with that request. Please try again.