Add renderer for text/plain media type
Taken from
@@ -10,7 +10,7 @@ from allauth.socialaccount.models import SocialAccount
from django.shortcuts import get_object_or_404
from rest_framework import decorators, permissions, status, viewsets
from rest_framework.decorators import detail_route
-from rest_framework.renderers import JSONRenderer
+from rest_framework.renderers import JSONRenderer, BaseRenderer
from rest_framework.response import Response
from readthedocs.builds.constants import BRANCH, TAG
@@ -34,6 +34,19 @@ from ..serializers import (
log = logging.getLogger(__name__)
+class PlainTextRenderer(BaseRenderer):
+ """Custom renderer for text/plain format.
+
+ charset is 'utf-8' by default.
+ """
+
+ media_type = 'text/plain'
+ format = 'txt'
+
+ def render(self, data, media_type=None, renderer_context=None):
+ return data.encode(self.charset)
+
+
class UserSelectViewSet(viewsets.ModelViewSet):
"""
