def jsonable_error(status=500, message='The Studio servers encountered an error'):
 def outer(func):
  @functools.wraps(func)
  def inner(request, *args, **kwargs):
   if request.is_ajax():
    content = dump_js_escaped_json({'error': message})
    return HttpResponse(content, content_type='application/json', status=status)
   else:
    return func(request, *args, **kwargs)
  return inner
 return outer

def jsonable_error ( status = 500 , message = 'The Studio servers encountered an error' ) : def outer ( func ) : @ functools . wraps ( func ) def inner ( request , * args , ** kwargs ) : if request . is_ajax ( ) : content = dump_js_escaped_json ( { 'error' : message } ) return HttpResponse ( content , content_type = 'application/json' , status = status ) else : return func ( request , * args , ** kwargs ) return inner return outer
a decorator to make an error view return an json-formatted message if it was requested via ajax .