Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2028 from getnikola/fix-atom-renderer
Fixing atom feed renderer for empty post lists.
  • Loading branch information
Kwpolska committed Sep 6, 2015
2 parents e971b1c + d8992df commit f68bf4f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nikola/nikola.py
Expand Up @@ -1822,7 +1822,7 @@ def atom_link(link_rel, link_type, link_href):
feed_id = lxml.etree.SubElement(feed_root, "id")
feed_id.text = self.abs_link(context["feedlink"])
feed_updated = lxml.etree.SubElement(feed_root, "updated")
feed_updated.text = post.formatted_date('webiso', datetime.datetime.now(tz=dateutil.tz.tzutc()))
feed_updated.text = utils.formatted_date('webiso', datetime.datetime.now(tz=dateutil.tz.tzutc()))
feed_author = lxml.etree.SubElement(feed_root, "author")
feed_author_name = lxml.etree.SubElement(feed_author, "name")
feed_author_name.text = self.config["BLOG_AUTHOR"](lang)
Expand Down
15 changes: 1 addition & 14 deletions nikola/post.py
Expand Up @@ -56,7 +56,6 @@
# for tearDown with _reload we cannot use 'from import' to get forLocaleBorg
import nikola.utils
from .utils import (
bytes_str,
current_time,
Functionary,
LOGGER,
Expand Down Expand Up @@ -324,19 +323,7 @@ def template_name(self):

def formatted_date(self, date_format, date=None):
"""Return the formatted date as unicode."""
date = date if date else self.date

if date_format == 'webiso':
# Formatted after RFC 3339 (web ISO 8501 profile) with Zulu
# zone desgignator for times in UTC and no microsecond precision.
fmt_date = date.replace(microsecond=0).isoformat().replace('+00:00', 'Z')
else:
fmt_date = date.strftime(date_format)

# Issue #383, this changes from py2 to py3
if isinstance(fmt_date, bytes_str):
fmt_date = fmt_date.decode('utf8')
return fmt_date
return utils.formatted_date(date_format, date if date else self.date)

def formatted_updated(self, date_format):
"""Return the updated date as unicode."""
Expand Down
17 changes: 16 additions & 1 deletion nikola/utils.py
Expand Up @@ -71,7 +71,7 @@
'adjust_name_for_index_path', 'adjust_name_for_index_link',
'NikolaPygmentsHTML', 'create_redirect', 'TreeNode',
'flatten_tree_structure', 'parse_escaped_hierarchical_category_name',
'join_hierarchical_category_path', 'indent')
'join_hierarchical_category_path', 'indent', 'formatted_date')

# Are you looking for 'generic_rss_renderer'?
# It's defined in nikola.nikola.Nikola (the site object).
Expand Down Expand Up @@ -1732,3 +1732,18 @@ def prefixed_lines():
for line in text.splitlines(True):
yield (prefix + line if predicate(line) else line)
return ''.join(prefixed_lines())


def formatted_date(date_format, date):
"""Return the formatted date as unicode."""
if date_format == 'webiso':
# Formatted after RFC 3339 (web ISO 8501 profile) with Zulu
# zone desgignator for times in UTC and no microsecond precision.
fmt_date = date.replace(microsecond=0).isoformat().replace('+00:00', 'Z')
else:
fmt_date = date.strftime(date_format)

# Issue #383, this changes from py2 to py3
if isinstance(fmt_date, bytes_str):
fmt_date = fmt_date.decode('utf8')
return fmt_date

0 comments on commit f68bf4f

Please sign in to comment.