<s> from django . core import serializers <EOL> from django . db import models <EOL> from django . forms . models import model_to_dict <EOL> from django . http import HttpResponse <EOL> class JsonResponseEncoder ( serializers . json . DjangoJSONEncoder ) : <EOL> """<STR_LIT>""" <EOL> def default ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , models . Model ) : <EOL> return self . encode ( model_to_dict ( obj ) ) <EOL> elif isinstance ( obj , models . query . QuerySet ) : <EOL> return serializers . serialize ( '<STR_LIT>' , obj ) <EOL> else : <EOL> return super ( JsonResponseEncoder , self ) . default ( obj ) <EOL> class JsonResponse ( HttpResponse ) : <EOL> def __init__ ( self , data = { } ) : <EOL> super ( JsonResponse , self ) . __init__ ( content_type = '<STR_LIT:application/json>' ) <EOL> self . set_content ( data ) <EOL> def set_content ( self , data ) : <EOL> json_encoder = JsonResponseEncoder ( separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) ) <EOL> content = json_encoder . encode ( data ) <EOL> self . content = content <EOL> class JsonResponseCreated ( JsonResponse ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseAccepted ( JsonResponse ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseBadRequest ( JsonResponse ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseWithStatus ( JsonResponse ) : <EOL> def __init__ ( self , error_message = '<STR_LIT>' , error_type = None , field_errors = None ) : <EOL> data = { <EOL> '<STR_LIT>' : error_type or self . status_code , <EOL> '<STR_LIT>' : error_message <EOL> } <EOL> if field_errors : <EOL> data [ '<STR_LIT>' ] = field_errors <EOL> super ( JsonResponseWithStatus , self ) . __init__ ( data ) <EOL> class JsonResponseSeeOther ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseForbidden ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseConflict ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseError ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseUnauthorized ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseNotFound ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> <EOL> class JsonResponseNotSupported ( JsonResponseWithStatus ) : <EOL> status_code = <NUM_LIT> </s>
