Ejemplo n.º 1
0
def _get_translated_link_in_content(content_id, version, target_link, lang):
    """
    For a given content service and version and link, return a related page in
    the desired language.
    """
    side_nav_content = sitemap_helper.get_content_navigation(
        content_id, version, lang)

    # Go through each level, and find the matching URL,
    # Once found, check if there is translated link.
    # NOTE: Only 3 levels of sections nesting are supported right now.
    for chapter_id, chapter in side_nav_content.iteritems():
        if 'sections' in chapter:
            for section in chapter['sections']:
                if 'link' in section:
                    link = section['link']
                    if target_link in link.values():
                        if lang in link:
                            return link[lang]

                elif 'sections' in section:
                    for sub_section in section['sections']:
                        if 'link' in sub_section:
                            link = sub_section['link']
                            if target_link in link.values():
                                if lang in link:
                                    return link[lang]
Ejemplo n.º 2
0
def content_links(context, content_id):
    current_lang_code = context.request.LANGUAGE_CODE
    docs_version = context.get('CURRENT_DOCS_VERSION', None)

    side_nav_content = sitemap_helper.get_content_navigation(
        content_id, docs_version, current_lang_code)

    return _common_context(
        context, {
            'side_nav_content': side_nav_content,
            'allow_search': context.get('allow_search', False),
            'search_url': context.get('search_url', None)
        })