From d8992df7baaac6b74213ca15143e95c1b3f20740 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 6 Sep 2015 14:47:32 +0200 Subject: [PATCH] Fixing atom feed renderer for empty post lists. --- nikola/nikola.py | 2 +- nikola/post.py | 15 +-------------- nikola/utils.py | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/nikola/nikola.py b/nikola/nikola.py index b476a4f29f..3c88f73c83 100644 --- a/nikola/nikola.py +++ b/nikola/nikola.py @@ -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) diff --git a/nikola/post.py b/nikola/post.py index 2416ef00bd..0d07cf74cc 100644 --- a/nikola/post.py +++ b/nikola/post.py @@ -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, @@ -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.""" diff --git a/nikola/utils.py b/nikola/utils.py index e5bd433e4e..f49ec5bdcc 100644 --- a/nikola/utils.py +++ b/nikola/utils.py @@ -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). @@ -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