Implement generic rest_dispatch method for new API.

(imported from commit 912ee803db03098f195d18648ab98401915fead6)
This commit is contained in:
Luke Faraone
2013-03-21 12:15:27 -07:00
parent 0c0f99ccc6
commit a49c37917a
3 changed files with 62 additions and 4 deletions

View File

@@ -1,6 +1,20 @@
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseNotAllowed
import simplejson
class HttpResponseUnauthorized(HttpResponse):
status_code = 401
def __init__(self, realm):
HttpResponse.__init__(self)
self["WWW-Authenticate"] = 'Basic realm="%s"' % realm
def json_method_not_allowed(methods):
resp = HttpResponseNotAllowed(methods)
resp.content = simplejson.dumps({"result": "error",
"msg": "Method Not Allowed",
"allowed_methods": methods})
return resp
def json_response(res_type="success", msg="", data={}, status=200):
content = {"result": res_type, "msg": msg}
content.update(data)