Author: mtredinnick
Date: 2007-02-10 02:36:39 -0600 (Sat, 10 Feb 2007)
New Revision: 4478
Modified:
django/trunk/AUTHORS
django/trunk/django/contrib/syndication/feeds.py
django/trunk/django/utils/feedgenerator.py
django/trunk/docs/syndication_feeds.txt
Log:
Fixed #2762 -- added copyright element support to RSS and Atom feeds. Patch
from Jonathan Buchanan.
Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS 2007-02-10 08:29:34 UTC (rev 4477)
+++ django/trunk/AUTHORS 2007-02-10 08:36:39 UTC (rev 4478)
@@ -44,6 +44,7 @@
[EMAIL PROTECTED]
akaihola
Andreas
+ [EMAIL PROTECTED]
[EMAIL PROTECTED]
David Ascher <http://ascher.ca/>
Arthur <[EMAIL PROTECTED]>
@@ -55,7 +56,7 @@
Paul Bissex <http://e-scribe.com/>
Simon Blanchard
Andrew Brehaut <http://brehaut.net/blog>
- [EMAIL PROTECTED]
+ Jonathan Buchanan <[EMAIL PROTECTED]>
Antonio Cavedoni <http://cavedoni.com/>
C8E
Chris Chamberlin <[EMAIL PROTECTED]>
Modified: django/trunk/django/contrib/syndication/feeds.py
===================================================================
--- django/trunk/django/contrib/syndication/feeds.py 2007-02-10 08:29:34 UTC
(rev 4477)
+++ django/trunk/django/contrib/syndication/feeds.py 2007-02-10 08:36:39 UTC
(rev 4478)
@@ -78,6 +78,7 @@
author_link = self.__get_dynamic_attr('author_link', obj),
author_email = self.__get_dynamic_attr('author_email', obj),
categories = self.__get_dynamic_attr('categories', obj),
+ feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
)
try:
@@ -116,5 +117,6 @@
author_email = author_email,
author_link = author_link,
categories = self.__get_dynamic_attr('item_categories', item),
+ item_copyright = self.__get_dynamic_attr('item_copyright',
item),
)
return feed
Modified: django/trunk/django/utils/feedgenerator.py
===================================================================
--- django/trunk/django/utils/feedgenerator.py 2007-02-10 08:29:34 UTC (rev
4477)
+++ django/trunk/django/utils/feedgenerator.py 2007-02-10 08:36:39 UTC (rev
4478)
@@ -40,7 +40,7 @@
"Base class for all syndication feeds. Subclasses should provide write()"
def __init__(self, title, link, description, language=None,
author_email=None,
author_name=None, author_link=None, subtitle=None, categories=None,
- feed_url=None):
+ feed_url=None, feed_copyright=None):
self.feed = {
'title': title,
'link': link,
@@ -52,12 +52,13 @@
'subtitle': subtitle,
'categories': categories or (),
'feed_url': feed_url,
+ 'feed_copyright': feed_copyright,
}
self.items = []
def add_item(self, title, link, description, author_email=None,
author_name=None, author_link=None, pubdate=None, comments=None,
- unique_id=None, enclosure=None, categories=()):
+ unique_id=None, enclosure=None, categories=(), item_copyright=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
@@ -75,6 +76,7 @@
'unique_id': unique_id,
'enclosure': enclosure,
'categories': categories or (),
+ 'item_copyright': item_copyright,
})
def num_items(self):
@@ -128,6 +130,8 @@
handler.addQuickElement(u"language", self.feed['language'])
for cat in self.feed['categories']:
handler.addQuickElement(u"category", cat)
+ if self.feed['feed_copyright'] is not None:
+ handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
@@ -212,6 +216,8 @@
handler.addQuickElement(u"subtitle", self.feed['subtitle'])
for cat in self.feed['categories']:
handler.addQuickElement(u"category", "", {u"term": cat})
+ if self.feed['feed_copyright'] is not None:
+ handler.addQuickElement(u"rights", self.feed['feed_copyright'])
self.write_items(handler)
handler.endElement(u"feed")
@@ -252,10 +258,14 @@
u"length": item['enclosure'].length,
u"type": item['enclosure'].mime_type})
- # Categories:
+ # Categories.
for cat in item['categories']:
handler.addQuickElement(u"category", u"", {u"term": cat})
+ # Rights.
+ if item['item_copyright'] is not None:
+ handler.addQuickElement(u"rights", item['item_copyright'])
+
handler.endElement(u"entry")
# This isolates the decision of what the system default is, so calling code can
Modified: django/trunk/docs/syndication_feeds.txt
===================================================================
--- django/trunk/docs/syndication_feeds.txt 2007-02-10 08:29:34 UTC (rev
4477)
+++ django/trunk/docs/syndication_feeds.txt 2007-02-10 08:36:39 UTC (rev
4478)
@@ -127,7 +127,7 @@
it two template context variables:
* ``{{ obj }}`` -- The current object (one of whichever objects you
- returned in ``items()``).
+ returned in ``items()``).
* ``{{ site }}`` -- A ``django.models.core.sites.Site`` object
representing the current site. This is useful for
``{{ site.domain }}`` or ``{{ site.name }}``.
@@ -478,6 +478,22 @@
categories = ("python", "django") # Hard-coded list of categories.
+ # COPYRIGHT NOTICE -- One of the following three is optional. The
+ # framework looks for them in this order.
+
+ def copyright(self, obj):
+ """
+ Takes the object returned by get_object() and returns the feed's
+ copyright notice as a normal Python string.
+ """
+
+ def copyright(self):
+ """
+ Returns the feed's copyright notice as a normal Python string.
+ """
+
+ copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright
notice.
+
# ITEMS -- One of the following three is required. The framework looks
# for them in this order.
@@ -659,7 +675,24 @@
item_categories = ("python", "django") # Hard-coded categories.
+ # ITEM COPYRIGHT NOTICE (only applicable to Atom feeds) -- One of the
+ # following three is optional. The framework looks for them in this
+ # order.
+ def item_copyright(self, obj):
+ """
+ Takes an item, as returned by items(), and returns the item's
+ copyright notice as a normal Python string.
+ """
+
+ def item_copyright(self):
+ """
+ Returns the copyright notice for every item in the feed.
+ """
+
+ item_copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded
copyright notice.
+
+
The low-level framework
=======================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---