diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-11-14 05:15:40 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-11-14 05:15:40 +0000 |
| commit | 74865663bbaddf4d2d8cd5472e2f137ebe0ec347 (patch) | |
| tree | 791def3ff75381f689a7a33c69a518520dd18520 /django | |
| parent | 7626cb058107ac1ecb0795162e4c9fc4f92356dd (diff) | |
Fixed #787 -- High-level syndication framework now picks up author details. Also updated documentation. Thanks, mattycakes
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1228 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/syndication/feeds.py | 19 | ||||
| -rw-r--r-- | django/utils/feedgenerator.py | 5 |
2 files changed, 21 insertions, 3 deletions
diff --git a/django/contrib/syndication/feeds.py b/django/contrib/syndication/feeds.py index 8b49334fec..49b34858dc 100644 --- a/django/contrib/syndication/feeds.py +++ b/django/contrib/syndication/feeds.py @@ -27,8 +27,11 @@ class Feed: except AttributeError: raise ImproperlyConfigured, "Give your %s class a get_absolute_url() method, or define an item_link() method in your Feed class." % item.__class__.__name__ - def __get_dynamic_attr(self, attname, obj): - attr = getattr(self, attname) + def __get_dynamic_attr(self, attname, obj, default=None): + try: + attr = getattr(self, attname) + except AttributeError: + return default if callable(attr): try: return attr(obj) @@ -59,6 +62,9 @@ class Feed: description = self.__get_dynamic_attr('description', obj), language = LANGUAGE_CODE.decode(), feed_url = add_domain(current_site, self.feed_url), + author_name = self.__get_dynamic_attr('author_name', obj), + author_link = self.__get_dynamic_attr('author_link', obj), + author_email = self.__get_dynamic_attr('author_email', obj), ) try: @@ -80,6 +86,12 @@ class Feed: length = str(self.__get_dynamic_attr('item_enclosure_length', item)).decode('utf-8'), mime_type = self.__get_dynamic_attr('item_enclosure_mime_type', item).decode('utf-8'), ) + author_name = self.__get_dynamic_attr('item_author_name', item) + if author_name is not None: + author_email = self.__get_dynamic_attr('item_author_email', item) + author_link = self.__get_dynamic_attr('item_author_link', item) + else: + author_email = author_link = None feed.add_item( title = title_template.render(Context({'obj': item, 'site': current_site})).decode('utf-8'), link = link, @@ -87,5 +99,8 @@ class Feed: unique_id = link, enclosure = enc, pubdate = self.__get_dynamic_attr('item_pubdate', item), + author_name = author_name, + author_email = author_email, + author_link = author_link, ) return feed diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index a8dd5c39df..22db5abe7f 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -58,7 +58,7 @@ class SyndicationFeed: self.items = [] def add_item(self, title, link, description, author_email=None, - author_name=None, pubdate=None, comments=None, + author_name=None, author_link=None, pubdate=None, comments=None, unique_id=None, enclosure=None, categories=()): """ Adds an item to the feed. All args are expected to be Python Unicode @@ -71,6 +71,7 @@ class SyndicationFeed: 'description': description, 'author_email': author_email, 'author_name': author_name, + 'author_link': author_link, 'pubdate': pubdate, 'comments': comments, 'unique_id': unique_id, @@ -226,6 +227,8 @@ class Atom1Feed(SyndicationFeed): handler.addQuickElement(u"name", item['author_name']) if item['author_email'] is not None: handler.addQuickElement(u"email", item['author_email']) + if item['author_link'] is not None: + handler.addQuickElement(u"uri", item['author_link']) handler.endElement(u"author") # Unique ID. |
