コード例 #1
0
    def get(self, request, format=None):
        project = self._get_project()
        version = self._get_version()
        version_compare_data = get_version_compare_data(
            project,
            version,
        )

        context = self._get_context()
        html = template_loader.get_template('restapi/footer.html').render(
            context,
            request,
        )

        resp_data = {
            'html': html,
            'show_version_warning': project.show_version_warning,
            'version_active': version.active,
            'version_compare': version_compare_data,
            'version_supported': version.supported,
        }

        # Allow folks to hook onto the footer response for various information
        # collection, or to modify the resp_data.
        footer_response.send(
            sender=None,
            request=request,
            context=context,
            resp_data=resp_data,
        )

        return Response(resp_data)
コード例 #2
0
    def get(self, request, format=None):
        project = self._get_project()
        version = self._get_version()
        version_compare_data = get_version_compare_data(
            project,
            version,
        )

        context = self._get_context()
        html = template_loader.get_template('restapi/footer.html').render(
            context,
            request,
        )

        resp_data = {
            'html': html,
            'show_version_warning': project.show_version_warning,
            'version_active': version.active,
            'version_compare': version_compare_data,
            'version_supported': version.supported,
        }

        # increase the page view count for the given page
        page_slug = request.GET.get('page', '')
        if page_slug and project.has_feature(Feature.STORE_PAGEVIEWS):
            increase_page_view_count.delay(
                project_slug=context['project'].slug,
                version_slug=context['version'].slug,
                path=page_slug
            )

        # Allow folks to hook onto the footer response for various information
        # collection, or to modify the resp_data.
        footer_response.send(
            sender=None,
            request=request,
            context=context,
            resp_data=resp_data,
        )

        return Response(resp_data)
コード例 #3
0
ファイル: footer_views.py プロジェクト: saadmk11/rtd-test
def footer_html(request):
    """Render and return footer markup."""
    # TODO refactor this function
    # pylint: disable=too-many-locals
    project_slug = request.GET.get('project', None)
    version_slug = request.GET.get('version', None)
    page_slug = request.GET.get('page', '')
    theme = request.GET.get('theme', False)
    docroot = request.GET.get('docroot', '')
    subproject = request.GET.get('subproject', False)
    source_suffix = request.GET.get('source_suffix', '.rst')

    # Hack in a fix for missing version slug deploy that went out a while back
    if version_slug == '':
        version_slug = LATEST

    new_theme = (theme == 'sphinx_rtd_theme')
    using_theme = (theme == 'default')
    project = get_object_or_404(Project, slug=project_slug)
    version = get_object_or_404(
        Version.objects.public(
            request.user,
            project=project,
            only_active=False,
        ),
        slug__iexact=version_slug,
    )
    main_project = project.main_language_project or project

    if page_slug and page_slug != 'index':
        if main_project.documentation_type == 'sphinx_htmldir':
            path = page_slug + '/'
        else:
            path = page_slug + '.html'
    else:
        path = ''

    version_compare_data = get_version_compare_data(project, version)

    context = {
        'project': project,
        'version': version,
        'path': path,
        'downloads': version.get_downloads(pretty=True),
        'current_version': version.verbose_name,
        'versions': project.ordered_active_versions(user=request.user),
        'main_project': main_project,
        'translations': main_project.translations.all(),
        'current_language': project.language,
        'using_theme': using_theme,
        'new_theme': new_theme,
        'settings': settings,
        'subproject': subproject,
        'github_edit_url': version.get_github_url(
            docroot,
            page_slug,
            source_suffix,
            'edit',
        ),
        'github_view_url': version.get_github_url(
            docroot,
            page_slug,
            source_suffix,
            'view',
        ),
        'gitlab_edit_url': version.get_gitlab_url(
            docroot,
            page_slug,
            source_suffix,
            'edit',
        ),
        'gitlab_view_url': version.get_gitlab_url(
            docroot,
            page_slug,
            source_suffix,
            'view',
        ),
        'bitbucket_url': version.get_bitbucket_url(
            docroot,
            page_slug,
            source_suffix,
        ),
        'theme': theme,
    }

    html = template_loader.get_template('restapi/footer.html').render(
        context,
        request,
    )
    resp_data = {
        'html': html,
        'show_version_warning': project.show_version_warning,
        'version_active': version.active,
        'version_compare': version_compare_data,
        'version_supported': version.supported,
    }

    # Allow folks to hook onto the footer response for various information
    # collection, or to modify the resp_data.
    footer_response.send(
        sender=None,
        request=request,
        context=context,
        resp_data=resp_data,
    )

    return Response(resp_data)
コード例 #4
0
ファイル: footer_views.py プロジェクト: rtfd/readthedocs.org
def footer_html(request):
    """Render and return footer markup."""
    # TODO refactor this function
    # pylint: disable=too-many-locals
    project_slug = request.GET.get('project', None)
    version_slug = request.GET.get('version', None)
    page_slug = request.GET.get('page', '')
    theme = request.GET.get('theme', False)
    docroot = request.GET.get('docroot', '')
    subproject = request.GET.get('subproject', False)
    source_suffix = request.GET.get('source_suffix', '.rst')

    # Hack in a fix for missing version slug deploy that went out a while back
    if version_slug == '':
        version_slug = LATEST

    new_theme = (theme == 'sphinx_rtd_theme')
    using_theme = (theme == 'default')
    project = get_object_or_404(Project, slug=project_slug)
    version = get_object_or_404(
        Version.objects.public(
            request.user,
            project=project,
            only_active=False,
        ),
        slug__iexact=version_slug,
    )
    main_project = project.main_language_project or project

    if page_slug and page_slug != 'index':
        if main_project.documentation_type == 'sphinx_htmldir':
            path = page_slug + '/'
        else:
            path = page_slug + '.html'
    else:
        path = ''

    version_compare_data = get_version_compare_data(project, version)

    context = {
        'project': project,
        'version': version,
        'path': path,
        'downloads': version.get_downloads(pretty=True),
        'current_version': version.verbose_name,
        'versions': project.ordered_active_versions(user=request.user),
        'main_project': main_project,
        'translations': main_project.translations.all(),
        'current_language': project.language,
        'using_theme': using_theme,
        'new_theme': new_theme,
        'settings': settings,
        'subproject': subproject,
        'github_edit_url': version.get_github_url(
            docroot,
            page_slug,
            source_suffix,
            'edit',
        ),
        'github_view_url': version.get_github_url(
            docroot,
            page_slug,
            source_suffix,
            'view',
        ),
        'gitlab_edit_url': version.get_gitlab_url(
            docroot,
            page_slug,
            source_suffix,
            'edit',
        ),
        'gitlab_view_url': version.get_gitlab_url(
            docroot,
            page_slug,
            source_suffix,
            'view',
        ),
        'bitbucket_url': version.get_bitbucket_url(
            docroot,
            page_slug,
            source_suffix,
        ),
        'theme': theme,
    }

    html = template_loader.get_template('restapi/footer.html').render(
        context,
        request,
    )
    resp_data = {
        'html': html,
        'show_version_warning': project.show_version_warning,
        'version_active': version.active,
        'version_compare': version_compare_data,
        'version_supported': version.supported,
    }

    # Allow folks to hook onto the footer response for various information
    # collection, or to modify the resp_data.
    footer_response.send(
        sender=None,
        request=request,
        context=context,
        resp_data=resp_data,
    )

    return Response(resp_data)