"""This module holds renderers for ``api`` app."""

from rest_framework.renderers import BaseRenderer, BrowsableAPIRenderer


class BrowsableAPIRendererWithoutForms(BrowsableAPIRenderer):
    """Renders the browsable api, but excludes the forms."""

    def get_context(self, *args, **kwargs):
        """Disable edit forms.

        For the parameters, see ``rest_framework.renderers.BrowsableAPIRenderer``
        """

        context = super().get_context(*args, **kwargs)
        context['display_edit_forms'] = False

        return context

    def show_form_for_method(self, view, method, request, obj):
        """We never want to do this! So just return False.

        For the parameters, see ``rest_framework.renderers.BrowsableAPIRenderer``
        """

        return False

    def get_rendered_html_form(self, data, view, method, request):
        """Why render _any_ forms at all. This method should return
        rendered HTML, so let's simply return an empty string.

        For the parameters, see ``rest_framework.renderers.BrowsableAPIRenderer``
        """

        return ""


class TemplatePDFRenderer(BaseRenderer):
    """A PDF renderer for use with templates.

    This rendered is only there to correctly handle the `Accept` header.

    """

    media_type = 'application/pdf'
    format = 'pdf'
    charset = None
    render_style = 'binary'

    # pylint: disable=unused-argument
    def render(self, data, media_type=None, renderer_context=None):
        """Return the provided data as it is

        For the parameters, see ``rest_framework.renderers.BaseRenderer``

        """

        return data
