summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Lexy Munroe) <eevee.git@veekun.com>2016-01-04 15:30:17 -0800
committerEevee (Lexy Munroe) <eevee.git@veekun.com>2016-01-04 15:30:17 -0800
commit33344f6ec9375c0e279fda1583acbcb97e35bac4 (patch)
treeffc328a0a178809ec28e6ac68b40337eea91e193
parent9dcf6e12cd9d26b170a36a513dd06d477635c1bf (diff)
downloadfeedgenerator-33344f6ec9375c0e279fda1583acbcb97e35bac4.tar.gz
Support Atom's <content> element
Adds a `content` kwarg to `add_item`, which will become the <content> of an Atom entry. For RSS, which has no equivalent, the content is silently ignored; this is consistent with how Atom ignores metadata like `ttl` that only exists in RSS.
-rw-r--r--feedgenerator/django/utils/feedgenerator.py7
-rw-r--r--tests_feedgenerator/test_feedgenerator.py5
2 files changed, 9 insertions, 3 deletions
diff --git a/feedgenerator/django/utils/feedgenerator.py b/feedgenerator/django/utils/feedgenerator.py
index 25b4ba1..eafb736 100644
--- a/feedgenerator/django/utils/feedgenerator.py
+++ b/feedgenerator/django/utils/feedgenerator.py
@@ -114,7 +114,7 @@ class SyndicationFeed(object):
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=(), item_copyright=None,
- ttl=None, **kwargs):
+ ttl=None, content=None, **kwargs):
"""
Adds an item to the feed. All args are expected to be Python Unicode
objects except pubdate, which is a datetime.datetime object, and
@@ -130,6 +130,7 @@ class SyndicationFeed(object):
'title': to_unicode(title),
'link': iri_to_uri(link),
'description': to_unicode(description),
+ 'content': to_unicode(content),
'author_email': to_unicode(author_email),
'author_name': to_unicode(author_name),
'author_link': iri_to_uri(author_link),
@@ -367,6 +368,10 @@ class Atom1Feed(SyndicationFeed):
if item['description'] is not None:
handler.addQuickElement("summary", item['description'], {"type": "html"})
+ # Full content.
+ if item['content'] is not None:
+ handler.addQuickElement("content", item['content'], {"type": "html"})
+
# Enclosure.
if item['enclosure'] is not None:
handler.addQuickElement("link", '',
diff --git a/tests_feedgenerator/test_feedgenerator.py b/tests_feedgenerator/test_feedgenerator.py
index 66441a5..45c64cd 100644
--- a/tests_feedgenerator/test_feedgenerator.py
+++ b/tests_feedgenerator/test_feedgenerator.py
@@ -24,7 +24,8 @@ FIXT_FEED = dict(
FIXT_ITEM = dict(
title="Hello",
link="http://www.holovaty.com/test/",
- description="Testing."
+ description="Testing.",
+ content="Full content of our testing entry.",
)
@@ -36,7 +37,7 @@ EXPECTED_RESULT_RSS = """<?xml version="1.0" encoding="utf-8"?>
</description><language>en</language><lastBuildDate>%DATE%</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description></item></channel></rss>"""
EXPECTED_RESULT_ATOM = """<?xml version="1.0" encoding="utf-8"?>
-<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Poynter E-Media Tidbits</title><link href="http://www.poynter.org/column.asp?id=31" rel="alternate"></link><id>http://www.poynter.org/column.asp?id=31</id><updated>%DATE%</updated><entry><title>Hello</title><link href="http://www.holovaty.com/test/" rel="alternate"></link><id>tag:www.holovaty.com:/test//</id><summary type="html">Testing.</summary></entry></feed>"""
+<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Poynter E-Media Tidbits</title><link href="http://www.poynter.org/column.asp?id=31" rel="alternate"></link><id>http://www.poynter.org/column.asp?id=31</id><updated>%DATE%</updated><entry><title>Hello</title><link href="http://www.holovaty.com/test/" rel="alternate"></link><id>tag:www.holovaty.com:/test//</id><summary type="html">Testing.</summary><content type="html">Full content of our testing entry.</content></entry></feed>"""
ENCODING = 'utf-8'