Skip to content
Permalink
Browse files

Making Codacy even more happy.

  • Loading branch information
felixfontein committed May 25, 2017
1 parent 270d1fb commit aa678b907509704ea3bf39fbbe2e9d066858c006
Showing with 38 additions and 38 deletions.
  1. +12 −12 nikola/plugins/task/authors.py
  2. +9 −9 nikola/plugins/task/categories.py
  3. +10 −10 nikola/plugins/task/sections.py
  4. +7 −7 nikola/plugins/task/tags.py
@@ -91,20 +91,20 @@ def classify(self, post, lang):
"""Classify the given post for the given language."""
return [post.author(lang=lang)]

def get_classification_friendly_name(self, author, lang, only_last_component=False):
def get_classification_friendly_name(self, classification, lang, only_last_component=False):
"""Extract a friendly name from the classification."""
return author
return classification

def get_overview_path(self, lang, dest_type='page'):
"""Return a path for the list of all classifications."""
return [self.site.config['AUTHOR_PATH'](lang)], 'always'

def get_path(self, author, lang, dest_type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""Return a path for the given classification."""
if self.site.config['SLUG_AUTHOR_PATH']:
slug = utils.slugify(author, lang)
slug = utils.slugify(classification, lang)
else:
slug = author
slug = classification
return [self.site.config['AUTHOR_PATH'](lang), slug], 'auto'

def provide_overview_context_and_uptodate(self, lang):
@@ -121,28 +121,28 @@ def provide_overview_context_and_uptodate(self, lang):
kw.update(context)
return context, kw

def provide_context_and_uptodate(self, author, lang, node=None):
def provide_context_and_uptodate(self, classification, lang, node=None):
"""Provide data for the context and the uptodate list for the list of the given classifiation."""
descriptions = self.site.config['AUTHOR_PAGES_DESCRIPTIONS']
kw = {
"messages": self.site.MESSAGES,
}
context = {
"author": author,
"title": kw["messages"][lang]["Posts by %s"] % author,
"description": descriptions[lang][author] if lang in descriptions and author in descriptions[lang] else None,
"author": classification,
"title": kw["messages"][lang]["Posts by %s"] % classification,
"description": descriptions[lang][classification] if lang in descriptions and classification in descriptions[lang] else None,
"pagekind": ["index" if self.show_list_as_index else "list", "author_page"],
}
if self.site.config["GENERATE_RSS"]:
rss_link = ("""<link rel="alternate" type="application/rss+xml" title="RSS for author {0} ({1})" href="{2}">""".format(
author, lang, self.site.link('author_rss', author, lang)))
classification, lang, self.site.link('author_rss', classification, lang)))
context['rss_link'] = rss_link
kw.update(context)
return context, kw

def get_other_language_variants(self, author, lang, classifications_per_language):
def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same author in other languages."""
return self.translation_manager.get_translations_as_list(author, lang)
return self.translation_manager.get_translations_as_list(classification, lang)

def postprocess_posts_per_classification(self, posts_per_classification_per_language, flat_hierarchy_per_lang=None, hierarchy_lookup_per_lang=None):
"""Rearrange, modify or otherwise use the list of posts per classification and per language."""
@@ -159,9 +159,9 @@ def provide_overview_context_and_uptodate(self, lang):
kw.update(context)
return context, kw

def provide_context_and_uptodate(self, cat, lang, node=None):
def provide_context_and_uptodate(self, classification, lang, node=None):
"""Provide data for the context and the uptodate list for the list of the given classifiation."""
cat_path = self.extract_hierarchy(cat)
cat_path = self.extract_hierarchy(classification)
kw = {
'category_path': self.site.config['CATEGORY_PATH'],
'category_prefix': self.site.config['CATEGORY_PREFIX'],
@@ -176,24 +176,24 @@ def provide_context_and_uptodate(self, cat, lang, node=None):
else:
children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]
subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]
friendly_name = self.get_classification_friendly_name(cat, lang)
friendly_name = self.get_classification_friendly_name(classification, lang)
context = {
"title": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
"description": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'].get(lang, {}).get(cat),
"title": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
"description": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'].get(lang, {}).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": friendly_name,
"category": cat,
"category": classification,
"category_path": cat_path,
"subcategories": subcats,
}
if self.show_list_as_index:
context["rss_link"] = """<link rel="alternate" type="application/rss+xml" type="application/rss+xml" title="RSS for tag {0} ({1})" href="{2}">""".format(friendly_name, lang, self.site.link("category_rss", cat, lang))
context["rss_link"] = """<link rel="alternate" type="application/rss+xml" type="application/rss+xml" title="RSS for tag {0} ({1})" href="{2}">""".format(friendly_name, lang, self.site.link("category_rss", classification, lang))
kw.update(context)
return context, kw

def get_other_language_variants(self, category, lang, classifications_per_language):
def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same category in other languages."""
return self.translation_manager.get_translations_as_list(category, lang)
return self.translation_manager.get_translations_as_list(classification, lang)

def postprocess_posts_per_classification(self, posts_per_classification_per_language, flat_hierarchy_per_lang=None, hierarchy_lookup_per_lang=None):
"""Rearrange, modify or otherwise use the list of posts per classification and per language."""
@@ -105,27 +105,27 @@ def get_path(self, section, lang, dest_type='page'):
return result + ['rss.xml'], 'never'
return result, 'always'

def provide_context_and_uptodate(self, section, lang, node=None):
def provide_context_and_uptodate(self, classification, lang, node=None):
"""Provide data for the context and the uptodate list for the list of the given classifiation."""
kw = {
"messages": self.site.MESSAGES,
}
section_name = self._get_section_name(section, lang)
section_name = self._get_section_name(classification, lang)
# Compose section title
section_title = section_name
posts_section_title = self.site.config['POSTS_SECTION_TITLE'](lang)
if isinstance(posts_section_title, dict):
if section in posts_section_title:
section_title = posts_section_title[section]
if classification in posts_section_title:
section_title = posts_section_title[classification]
elif isinstance(posts_section_title, (utils.bytes_str, utils.unicode_str)):
section_title = posts_section_title
section_title = section_title.format(name=section_name)
# Compose context
context = {
"title": section_title,
"description": self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang)[section] if section in self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang) else "",
"description": self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang)[classification] if classification in self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang) else "",
"pagekind": ["section_page", "index" if self.show_list_as_index else "list"],
"section": section,
"section": classification,
}
kw.update(context)
return context, kw
@@ -143,9 +143,9 @@ def postprocess_posts_per_classification(self, posts_per_classification_per_lang
self.enable_for_lang[lang] = (len(sections) > 1)
self.translation_manager.read_from_config(self.site, 'POSTS_SECTION', posts_per_classification_per_language, False)

def should_generate_classification_page(self, dirname, post_list, lang):
def should_generate_classification_page(self, classification, post_list, lang):
"""Only generates list of posts for classification if this function returns True."""
short_destination = dirname + '/' + self.site.config['INDEX_FILE']
short_destination = classification + '/' + self.site.config['INDEX_FILE']
# If there is an index.html pending to be created from a page, do not generate the section page.
# The section page would be useless anyways. (via Issue #2613)
for post in self.site.timeline:
@@ -155,6 +155,6 @@ def should_generate_classification_page(self, dirname, post_list, lang):
return False
return True

def get_other_language_variants(self, dirname, lang, classifications_per_language):
def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same section in other languages."""
return self.translation_manager.get_translations_as_list(dirname, lang)
return self.translation_manager.get_translations_as_list(classification, lang)
@@ -138,7 +138,7 @@ def provide_overview_context_and_uptodate(self, lang):
kw.update(context)
return context, kw

def provide_context_and_uptodate(self, tag, lang, node=None):
def provide_context_and_uptodate(self, classification, lang, node=None):
"""Provide data for the context and the uptodate list for the list of the given classifiation."""
kw = {
"tag_path": self.site.config['TAG_PATH'],
@@ -149,19 +149,19 @@ def provide_context_and_uptodate(self, tag, lang, node=None):
"tag_pages_titles": self.site.config['TAG_PAGES_TITLES'],
}
context = {
"title": self.site.config['TAG_PAGES_TITLES'].get(lang, {}).get(tag, self.site.MESSAGES[lang]["Posts about %s"] % tag),
"description": self.site.config['TAG_PAGES_DESCRIPTIONS'].get(lang, {}).get(tag),
"title": self.site.config['TAG_PAGES_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % classification),
"description": self.site.config['TAG_PAGES_DESCRIPTIONS'].get(lang, {}).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": tag,
"tag": classification,
}
if self.show_list_as_index:
context["rss_link"] = """<link rel="alternate" type="application/rss+xml" type="application/rss+xml" title="RSS for tag {0} ({1})" href="{2}">""".format(tag, lang, self.site.link("tag_rss", tag, lang))
context["rss_link"] = """<link rel="alternate" type="application/rss+xml" type="application/rss+xml" title="RSS for tag {0} ({1})" href="{2}">""".format(classification, lang, self.site.link("tag_rss", classification, lang))
kw.update(context)
return context, kw

def get_other_language_variants(self, tag, lang, classifications_per_language):
def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same tag in other languages."""
return self.translation_manager.get_translations_as_list(tag, lang)
return self.translation_manager.get_translations_as_list(classification, lang)

def postprocess_posts_per_classification(self, posts_per_classification_per_language, flat_hierarchy_per_lang=None, hierarchy_lookup_per_lang=None):
"""Rearrange, modify or otherwise use the list of posts per classification and per language."""

0 comments on commit aa678b9

Please sign in to comment.
You can’t perform that action at this time.