# Buggy code
def postprocess_posts_per_classification(
    self,
    posts_per_archive_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."""
    # Build a lookup table for archive navigation, if we’ll need one.
    if self.site.config["CREATE_ARCHIVE_NAVIGATION"]:
        if flat_hierarchy_per_lang is None:
            raise ValueError("Archives need flat_hierarchy_per_lang")
        self.archive_navigation = {}
        for lang, flat_hierarchy in flat_hierarchy_per_lang.items():
            self.archive_navigation[lang] = defaultdict(list)
            for node in flat_hierarchy:
                if not self.site.config["SHOW_UNTRANSLATED_POSTS"]:
                    if not [
                        x
                        for x in posts_per_archive_per_language[lang][
                            node.classification_name
                        ]
                        if x.is_translation_available(lang)
                    ]:
                        continue
                self.archive_navigation[lang][len(node.classification_path)].append(
                    node.classification_name
                )

            # We need to sort it. Natsort means it’s year 10000 compatible!
            for k, v in self.archive_navigation[lang].items():
                self.archive_navigation[lang][k] = natsort.natsorted(
                    v, alg=natsort.ns.F | natsort.ns.IC
                )

    return super(Archive, self).postprocess_posts_per_classification(
        posts_per_archive_per_language,
        flat_hierarchy_per_lang,
        hierarchy_lookup_per_lang,
    )


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
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."""
    # Build a lookup table for archive navigation, if we’ll need one.
    if self.site.config["CREATE_ARCHIVE_NAVIGATION"]:
        if flat_hierarchy_per_lang is None:
            raise ValueError("Archives need flat_hierarchy_per_lang")
        self.archive_navigation = {}
        for lang, flat_hierarchy in flat_hierarchy_per_lang.items():
            self.archive_navigation[lang] = defaultdict(list)
            for node in flat_hierarchy:
                if not self.site.config["SHOW_UNTRANSLATED_POSTS"]:
                    if not [
                        x
                        for x in posts_per_classification_per_language[lang][
                            node.classification_name
                        ]
                        if x.is_translation_available(lang)
                    ]:
                        continue
                self.archive_navigation[lang][len(node.classification_path)].append(
                    node.classification_name
                )

            # We need to sort it. Natsort means it’s year 10000 compatible!
            for k, v in self.archive_navigation[lang].items():
                self.archive_navigation[lang][k] = natsort.natsorted(
                    v, alg=natsort.ns.F | natsort.ns.IC
                )

    return super(Archive, self).postprocess_posts_per_classification(
        posts_per_classification_per_language,
        flat_hierarchy_per_lang,
        hierarchy_lookup_per_lang,
    )