<s> from django . http import HttpResponse <EOL> from django . utils import simplejson <EOL> class JsonResponse ( HttpResponse ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data ) : <EOL> super ( JsonResponse , self ) . __init__ ( content = simplejson . dumps ( data ) , mimetype = '<STR_LIT:application/json>' ) <EOL> def as_json ( errors ) : <EOL> return dict ( ( k , map ( unicode , v ) ) for k , v in errors . items ( ) ) <EOL> def ajax_request ( func ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( request , * args , ** kwargs ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> response = func ( request , * args , ** kwargs ) <EOL> else : <EOL> response = { '<STR_LIT:error>' : { '<STR_LIT:type>' : <NUM_LIT> , <EOL> '<STR_LIT:message>' : '<STR_LIT>' } } <EOL> if isinstance ( response , dict ) : <EOL> resp = JsonResponse ( response ) <EOL> if '<STR_LIT:error>' in response : <EOL> resp . status_code = response [ '<STR_LIT:error>' ] . get ( '<STR_LIT:type>' , <NUM_LIT> ) <EOL> return resp <EOL> return response <EOL> wrapper . __name__ = func . __name__ <EOL> wrapper . __module__ = func . __module__ <EOL> wrapper . __doc__ = func . __doc__ <EOL> return wrapper </s>
