diff options
| author | Eevee (Lexy Munroe) <eevee.git@veekun.com> | 2016-01-04 15:38:50 -0800 |
|---|---|---|
| committer | Eevee (Lexy Munroe) <eevee.git@veekun.com> | 2016-01-04 15:38:50 -0800 |
| commit | 09422f055d127e17e0442511670b6194918443fe (patch) | |
| tree | 5806a1f97ef467f54ccc3d7fe99545a761cacb0a | |
| parent | 3bf4c0b319893fc1bff3b5dba2c23874252de3df (diff) | |
| download | feedgenerator-09422f055d127e17e0442511670b6194918443fe.tar.gz | |
Support giving an explicit <updated> for Atom
| -rw-r--r-- | feedgenerator/django/utils/feedgenerator.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/feedgenerator/django/utils/feedgenerator.py b/feedgenerator/django/utils/feedgenerator.py index f10aed2..04b7d73 100644 --- a/feedgenerator/django/utils/feedgenerator.py +++ b/feedgenerator/django/utils/feedgenerator.py @@ -114,11 +114,11 @@ 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, content=None, **kwargs): + ttl=None, content=None, updateddate=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 - enclosure, which is an instance of the Enclosure class. + objects except pubdate and updateddate, which are datetime.datetime + objects, and enclosure, which is an instance of the Enclosure class. """ to_unicode = lambda s: force_text(s, strings_only=True) if categories: @@ -135,6 +135,7 @@ class SyndicationFeed(object): 'author_name': to_unicode(author_name), 'author_link': iri_to_uri(author_link), 'pubdate': pubdate, + 'updateddate': updateddate, 'comments': to_unicode(comments), 'unique_id': to_unicode(unique_id), 'enclosure': enclosure, @@ -191,10 +192,11 @@ class SyndicationFeed(object): def latest_post_date(self): """ - Returns the latest item's pubdate. If none of them have a pubdate, - this returns the current date/time. + Returns the latest item's pubdate or updateddate. If no item has either + date, returns the current date/time. """ updates = [i['pubdate'] for i in self.items if i['pubdate'] is not None] + updates.extend(i['updateddate'] for i in self.items if i['updateddate'] is not None) if len(updates) > 0: updates.sort() return updates[-1] @@ -346,6 +348,8 @@ class Atom1Feed(SyndicationFeed): handler.addQuickElement("link", "", {"href": item['link'], "rel": "alternate"}) if item['pubdate'] is not None: handler.addQuickElement("published", rfc3339_date(item['pubdate'])) + if item['updateddate'] is not None: + handler.addQuickElement("updated", rfc3339_date(item['updateddate'])) # Author information. if item['author_name'] is not None: |
