Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2762 -- added copyright element support to RSS and Atom feeds.…

… Patch

from Jonathan Buchanan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4478 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 937f3190baabb5c98398b391bcf8250bbb738da5 1 parent fefcbbf
Malcolm Tredinnick authored
3  AUTHORS
@@ -44,6 +44,7 @@ answer newbie questions, and generally made Django that much better:
44 44
     adurdin@gmail.com
45 45
     akaihola
46 46
     Andreas
  47
+    andy@jadedplanet.net
47 48
     ant9000@netwise.it
48 49
     David Ascher <http://ascher.ca/>
49 50
     Arthur <avandorp@gmail.com>
@@ -55,7 +56,7 @@ answer newbie questions, and generally made Django that much better:
55 56
     Paul Bissex <http://e-scribe.com/>
56 57
     Simon Blanchard
57 58
     Andrew Brehaut <http://brehaut.net/blog>
58  
-    andy@jadedplanet.net
  59
+    Jonathan Buchanan <jonathan.buchanan@gmail.com>
59 60
     Antonio Cavedoni <http://cavedoni.com/>
60 61
     C8E
61 62
     Chris Chamberlin <dja@cdc.msbx.net>
2  django/contrib/syndication/feeds.py
@@ -78,6 +78,7 @@ def get_feed(self, url=None):
78 78
             author_link = self.__get_dynamic_attr('author_link', obj),
79 79
             author_email = self.__get_dynamic_attr('author_email', obj),
80 80
             categories = self.__get_dynamic_attr('categories', obj),
  81
+            feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
81 82
         )
82 83
 
83 84
         try:
@@ -116,5 +117,6 @@ def get_feed(self, url=None):
116 117
                 author_email = author_email,
117 118
                 author_link = author_link,
118 119
                 categories = self.__get_dynamic_attr('item_categories', item),
  120
+                item_copyright = self.__get_dynamic_attr('item_copyright', item),
119 121
             )
120 122
         return feed
16  django/utils/feedgenerator.py
@@ -40,7 +40,7 @@ class SyndicationFeed(object):
40 40
     "Base class for all syndication feeds. Subclasses should provide write()"
41 41
     def __init__(self, title, link, description, language=None, author_email=None,
42 42
             author_name=None, author_link=None, subtitle=None, categories=None,
43  
-            feed_url=None):
  43
+            feed_url=None, feed_copyright=None):
44 44
         self.feed = {
45 45
             'title': title,
46 46
             'link': link,
@@ -52,12 +52,13 @@ def __init__(self, title, link, description, language=None, author_email=None,
52 52
             'subtitle': subtitle,
53 53
             'categories': categories or (),
54 54
             'feed_url': feed_url,
  55
+            'feed_copyright': feed_copyright,
55 56
         }
56 57
         self.items = []
57 58
 
58 59
     def add_item(self, title, link, description, author_email=None,
59 60
         author_name=None, author_link=None, pubdate=None, comments=None,
60  
-        unique_id=None, enclosure=None, categories=()):
  61
+        unique_id=None, enclosure=None, categories=(), item_copyright=None):
61 62
         """
62 63
         Adds an item to the feed. All args are expected to be Python Unicode
63 64
         objects except pubdate, which is a datetime.datetime object, and
@@ -75,6 +76,7 @@ def add_item(self, title, link, description, author_email=None,
75 76
             'unique_id': unique_id,
76 77
             'enclosure': enclosure,
77 78
             'categories': categories or (),
  79
+            'item_copyright': item_copyright,
78 80
         })
79 81
 
80 82
     def num_items(self):
@@ -128,6 +130,8 @@ def write(self, outfile, encoding):
128 130
             handler.addQuickElement(u"language", self.feed['language'])
129 131
         for cat in self.feed['categories']:
130 132
             handler.addQuickElement(u"category", cat)
  133
+        if self.feed['feed_copyright'] is not None:
  134
+            handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
131 135
         self.write_items(handler)
132 136
         self.endChannelElement(handler)
133 137
         handler.endElement(u"rss")
@@ -212,6 +216,8 @@ def write(self, outfile, encoding):
212 216
             handler.addQuickElement(u"subtitle", self.feed['subtitle'])
213 217
         for cat in self.feed['categories']:
214 218
             handler.addQuickElement(u"category", "", {u"term": cat})
  219
+        if self.feed['feed_copyright'] is not None:
  220
+            handler.addQuickElement(u"rights", self.feed['feed_copyright'])
215 221
         self.write_items(handler)
216 222
         handler.endElement(u"feed")
217 223
 
@@ -252,10 +258,14 @@ def write_items(self, handler):
252 258
                      u"length": item['enclosure'].length,
253 259
                      u"type": item['enclosure'].mime_type})
254 260
 
255  
-            # Categories:
  261
+            # Categories.
256 262
             for cat in item['categories']:
257 263
                 handler.addQuickElement(u"category", u"", {u"term": cat})
258 264
 
  265
+            # Rights.
  266
+            if item['item_copyright'] is not None:
  267
+                handler.addQuickElement(u"rights", item['item_copyright'])
  268
+
259 269
             handler.endElement(u"entry")
260 270
 
261 271
 # This isolates the decision of what the system default is, so calling code can
35  docs/syndication_feeds.txt
@@ -127,7 +127,7 @@ put into those elements.
127 127
       it two template context variables:
128 128
 
129 129
           * ``{{ obj }}`` -- The current object (one of whichever objects you
130  
-            returned in ``items()``). 
  130
+            returned in ``items()``).
131 131
           * ``{{ site }}`` -- A ``django.models.core.sites.Site`` object
132 132
             representing the current site. This is useful for
133 133
             ``{{ site.domain }}`` or ``{{ site.name }}``.
@@ -478,6 +478,22 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
478 478
 
479 479
         categories = ("python", "django") # Hard-coded list of categories.
480 480
 
  481
+        # COPYRIGHT NOTICE -- One of the following three is optional. The
  482
+        # framework looks for them in this order.
  483
+
  484
+        def copyright(self, obj):
  485
+            """
  486
+            Takes the object returned by get_object() and returns the feed's
  487
+            copyright notice as a normal Python string.
  488
+            """
  489
+
  490
+        def copyright(self):
  491
+            """
  492
+            Returns the feed's copyright notice as a normal Python string.
  493
+            """
  494
+
  495
+        copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice.
  496
+
481 497
         # ITEMS -- One of the following three is required. The framework looks
482 498
         # for them in this order.
483 499
 
@@ -659,6 +675,23 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
659 675
 
660 676
         item_categories = ("python", "django") # Hard-coded categories.
661 677
 
  678
+        # ITEM COPYRIGHT NOTICE (only applicable to Atom feeds) -- One of the
  679
+        # following three is optional. The framework looks for them in this
  680
+        # order.
  681
+
  682
+        def item_copyright(self, obj):
  683
+            """
  684
+            Takes an item, as returned by items(), and returns the item's
  685
+            copyright notice as a normal Python string.
  686
+            """
  687
+
  688
+        def item_copyright(self):
  689
+            """
  690
+            Returns the copyright notice for every item in the feed.
  691
+            """
  692
+
  693
+        item_copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice.
  694
+
662 695
 
663 696
 The low-level framework
664 697
 =======================

0 notes on commit 937f319

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