Move json response functions into their own file

(imported from commit 91a786849bfa30dcacecef6b8339d8f1a9365156)
This commit is contained in:
Zev Benjamin 2012-11-06 14:31:53 -05:00
parent 7bbde14d78
commit b278db110f
2 changed files with 15 additions and 12 deletions

14
zephyr/lib/response.py Normal file
View File

@ -0,0 +1,14 @@
from django.http import HttpResponse
import simplejson
def json_response(res_type="success", msg="", data={}, status=200):
content = {"result": res_type, "msg": msg}
content.update(data)
return HttpResponse(content=simplejson.dumps(content),
mimetype='application/json', status=status)
def json_success(data={}):
return json_response(data=data)
def json_error(msg, data={}, status=400):
return json_response(res_type="error", msg=msg, data=data, status=status)

View File

@ -22,6 +22,7 @@ from django.views.decorators.csrf import csrf_exempt
from zephyr.decorator import asynchronous
from zephyr.lib.query import last_n
from zephyr.lib.avatar import gravatar_hash
from zephyr.lib.response import json_success, json_error
from confirmation.models import Confirmation
@ -76,18 +77,6 @@ def authenticated_json_view(view_func):
return view_func(request, *args, **kwargs)
return _wrapped_view_func
def json_response(res_type="success", msg="", data={}, status=200):
content = {"result": res_type, "msg": msg}
content.update(data)
return HttpResponse(content=simplejson.dumps(content),
mimetype='application/json', status=status)
def json_success(data={}):
return json_response(data=data)
def json_error(msg, data={}, status=400):
return json_response(res_type="error", msg=msg, data=data, status=status)
def get_stream(stream_name, realm):
try:
return Stream.objects.get(name__iexact=stream_name, realm=realm)