Skip to content
Permalink
Browse files
Making codacy happy (hopefully).
  • Loading branch information
felixfontein committed Dec 3, 2016
1 parent d446e88 commit ca73d7095a1ecd5804df5d4cc5f59ec09439caa3
@@ -663,7 +663,7 @@ def get_classification_friendly_name(self, classification, lang, only_last_compo
"""
raise NotImplementedError()

def get_overview_path(self, lang, type='page'):
def get_overview_path(self, lang, dest_type='page'):
"""A path handler for the classification overview.
Must return one or two values (in this order):
@@ -679,11 +679,11 @@ def get_overview_path(self, lang, type='page'):
be ignored by this handler. The return value will be modified based on
the PRETTY_URLS and INDEX_FILE settings.
Type can be either 'page', 'feed' (for Atom feed) or 'rss'.
`dest_type` can be either 'page', 'feed' (for Atom feed) or 'rss'.
"""
raise NotImplementedError()

def get_path(self, classification, lang, type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""A path handler for the given classification.
Must return one to three values (in this order):
@@ -702,7 +702,7 @@ def get_path(self, classification, lang, type='page'):
be ignored by this handler. The return value will be modified based on
the PRETTY_URLS and INDEX_FILE settings.
Type can be either 'page', 'feed' (for Atom feed) or 'rss'.
`dest_type` can be either 'page', 'feed' (for Atom feed) or 'rss'.
For hierarchical taxonomies, the result of extract_hierarchy is provided
as `classification`. For non-hierarchical taxonomies, the classification
@@ -202,7 +202,7 @@ def _compute_number_of_pages(filtered_posts, posts_count):
"""Given a list of posts and the maximal number of posts per page, computes the number of pages needed."""
return min(1, (len(filtered_posts) + posts_count - 1) // posts_count)

def _postprocess_path(self, path, lang, append_index='auto', type='page', page_info=None):
def _postprocess_path(self, path, lang, append_index='auto', dest_type='page', page_info=None):
"""Postprocess a generated path.
Takes the path `path` for language `lang`, and postprocesses it.
@@ -212,25 +212,25 @@ def _postprocess_path(self, path, lang, append_index='auto', type='page', page_i
`site.config['PRETTY_URLS']`.
It also modifies/adds the extension of the last path element resp.
`site.config['INDEX_FILE']` depending on `type`, which can be
`site.config['INDEX_FILE']` depending on `dest_type`, which can be
`'feed'`, `'rss'` or `'page'`.
Finally, if `type` is `'page'`, `page_info` can be `None` or a tuple
Finally, if `dest_type` is `'page'`, `page_info` can be `None` or a tuple
of two integers: the page number and the number of pages. This will
be used to append the correct page number by calling
`utils.adjust_name_for_index_path_list` and
`utils.get_displayed_page_number`.
"""
# Forcing extension for Atom feeds and RSS feeds
force_extension = None
if type == 'feed':
if dest_type == 'feed':
force_extension = '.atom'
elif type == 'rss':
elif dest_type == 'rss':
force_extension = '.xml'
# Determine how to extend path
path = [_f for _f in path if _f]
if force_extension is not None:
if len(path) == 0 and type == 'rss':
if len(path) == 0 and dest_type == 'rss':
path = ['rss']
elif len(path) == 0 or append_index == 'always':
path = path + [os.path.splitext(self.site.config['INDEX_FILE'])[0]]
@@ -241,7 +241,7 @@ def _postprocess_path(self, path, lang, append_index='auto', type='page', page_i
path[-1] += '.html'
# Create path
result = [_f for _f in [self.site.config['TRANSLATIONS'][lang]] + path if _f]
if page_info is not None and type == 'page':
if page_info is not None and dest_type == 'page':
result = utils.adjust_name_for_index_path_list(result,
page_info[0],
utils.get_displayed_page_number(page_info[0], page_info[1], self.site),
@@ -264,14 +264,14 @@ def _taxonomy_index_path(self, lang, taxonomy):
"""Return path to the classification overview."""
result = taxonomy.get_overview_path(lang)
path, append_index, _ = self._parse_path_result(result)
return self._postprocess_path(path, lang, append_index=append_index, type='list')
return self._postprocess_path(path, lang, append_index=append_index, dest_type='list')

def _taxonomy_path(self, name, lang, taxonomy, type='page'):
def _taxonomy_path(self, name, lang, taxonomy, dest_type='page'):
"""Return path to a classification."""
if taxonomy.has_hierarchy:
result = taxonomy.get_path(taxonomy.extract_hierarchy(name), lang, type=type)
result = taxonomy.get_path(taxonomy.extract_hierarchy(name), lang, dest_type=dest_type)
else:
result = taxonomy.get_path(name, lang, type=type)
result = taxonomy.get_path(name, lang, dest_type=dest_type)
path, append_index, page = self._parse_path_result(result)
page_info = None
if not taxonomy.show_list_as_index and page is not None:
@@ -280,15 +280,15 @@ def _taxonomy_path(self, name, lang, taxonomy, type='page'):
number_of_pages = self._compute_number_of_pages(self._get_filtered_list(name, lang), self.site.config['INDEX_DISPLAY_POST_COUNT'])
self.site.page_count_per_classification[taxonomy.classification_name][lang][name] = number_of_pages
page_info = (page, number_of_pages)
return self._postprocess_path(path, lang, append_index=append_index, type=type, page_info=page_info)
return self._postprocess_path(path, lang, append_index=append_index, dest_type=dest_type, page_info=page_info)

def _taxonomy_atom_path(self, name, lang, taxonomy):
"""Return path to a classification Atom feed."""
return self._taxonomy_path(name, lang, taxonomy, type='feed')
return self._taxonomy_path(name, lang, taxonomy, dest_type='feed')

def _taxonomy_rss_path(self, name, lang, taxonomy):
"""Return path to a classification RSS feed."""
return self._taxonomy_path(name, lang, taxonomy, type='rss')
return self._taxonomy_path(name, lang, taxonomy, dest_type='rss')

def _register_path_handlers(self, taxonomy):
self.site.register_path_handler('{0}_index'.format(taxonomy.classification_name), lambda name, lang: self._taxonomy_index_path(lang, taxonomy))
@@ -102,7 +102,7 @@ def get_classification_friendly_name(self, classification, lang, only_last_compo
# Fallback
return '/'.join(classification)

def get_path(self, classification, lang, type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""A path handler for the given classification."""
components = [self.site.config['ARCHIVE_PATH']]
if classification:
@@ -71,11 +71,11 @@ def get_classification_friendly_name(self, author, lang, only_last_component=Fal
"""Extract a friendly name from the classification."""
return author

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

def get_path(self, author, lang, type='page'):
def get_path(self, author, lang, dest_type='page'):
"""A path handler for the given classification."""
if self.site.config['SLUG_AUTHOR_PATH']:
slug = utils.slugify(author, lang)
@@ -27,10 +27,6 @@
"""Render the category pages and feeds."""

from __future__ import unicode_literals
try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin # NOQA

from nikola.plugin_categories import Taxonomy
from nikola import utils
@@ -79,7 +75,7 @@ def get_classification_friendly_name(self, classification, lang, only_last_compo
classification = self.extract_hierarchy(classification)
return classification[-1] if classification else ''

def get_overview_path(self, lang, type='page'):
def get_overview_path(self, lang, dest_type='page'):
"""A path handler for the list of all classifications."""
if self.site.config['CATEGORIES_INDEX_PATH'][lang]:
return [_f for _f in [self.site.config['CATEGORIES_INDEX_PATH'][lang]] if _f], 'never'
@@ -105,7 +101,7 @@ def slugify_category_name(self, path, lang):
result = ['-'.join(result)]
return result

def get_path(self, classification, lang, type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""A path handler for the given classification."""
return ([_f for _f in [self.site.config['CATEGORY_PATH'][lang]] if _f] + self.slugify_category_name(classification, lang), 'auto')

@@ -135,7 +131,7 @@ def provide_overview_context_and_uptodate(self, lang):
kw.update(context)
return context, kw

def provide_context_and_uptodate(self, cat, lang, node):
def provide_context_and_uptodate(self, cat, 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)
kw = {
@@ -66,13 +66,13 @@ def get_classification_friendly_name(self, classification, lang, only_last_compo
"""Extract a friendly name from the classification."""
return self.site.config["BLOG_TITLE"](lang)

def get_path(self, classification, lang, type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""A path handler for the given classification."""
if type == 'rss':
if dest_type == 'rss':
return [self.site.config['RSS_PATH']], True
# 'page' (index) or 'feed' (Atom)
page_number = None
if type == 'page':
if dest_type == 'page':
# Interpret argument as page number
try:
page_number = int(classification)
@@ -68,7 +68,7 @@ def get_classification_friendly_name(self, dirname, lang, only_last_component=Fa
"""Extract a friendly name from the classification."""
return dirname

def get_path(self, hierarchy, lang, type='page'):
def get_path(self, hierarchy, lang, dest_type='page'):
"""A path handler for the given classification."""
return hierarchy, 'always'

@@ -78,13 +78,12 @@ def get_classification_friendly_name(self, section, lang, only_last_component=Fa
"""Extract a friendly name from the classification."""
return self._get_section_name(section, lang)

def get_path(self, section, lang, type='page'):
def get_path(self, section, lang, dest_type='page'):
"""A path handler for the given classification."""
result = [_f for _f in [section] if _f]
if type == 'rss':
if dest_type == 'rss':
return result + ['rss'], 'never'
else:
return result, 'always'
return result, 'always'

def provide_context_and_uptodate(self, section, lang, node=None):
"""Provide data for the context and the uptodate list for the list of the given classifiation."""
@@ -29,10 +29,6 @@
from __future__ import unicode_literals
import json
import os
try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin # NOQA

from nikola.plugin_categories import Task
from nikola import utils
@@ -27,10 +27,6 @@
"""Render the tag pages and feeds."""

from __future__ import unicode_literals
try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin # NOQA

from nikola.plugin_categories import Taxonomy
from nikola import utils
@@ -83,14 +79,14 @@ def slugify_tag_name(self, name, lang):
name = utils.slugify(name, lang)
return name

def get_overview_path(self, lang, type='page'):
def get_overview_path(self, lang, dest_type='page'):
"""A path handler for the list of all classifications."""
if self.site.config['TAGS_INDEX_PATH'][lang]:
return [_f for _f in [self.site.config['TAGS_INDEX_PATH'][lang]] if _f], 'never'
else:
return [_f for _f in [self.site.config['TAG_PATH'][lang]] if _f], 'always'

def get_path(self, classification, lang, type='page'):
def get_path(self, classification, lang, dest_type='page'):
"""A path handler for the given classification."""
return [_f for _f in [
self.site.config['TAG_PATH'][lang],

0 comments on commit ca73d70

Please sign in to comment.