andela/ah-infinity-stones

View on GitHub
authors/apps/comments/renderers.py

Summary

Maintainability
A
0 mins
Test Coverage
import json

from rest_framework.renderers import JSONRenderer

class CommentJSONRenderer(JSONRenderer):
    charset = 'utf-8'

    def render(self, data, media_type=None, renderer_context=None):
        # If the view throws an error (such as the user can't be authenticated
        # or something similar), `data` will contain an `errors` key. We want
        # the default JSONRenderer to handle rendering errors, so we need to
        # check for this case.


        # Finally, we can render our data under the "user" namespace.
        return json.dumps({
            'comments': data
        })