From b278db110f25e54b7b2beda9b33096891e460260 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Tue, 6 Nov 2012 14:31:53 -0500 Subject: [PATCH] Move json response functions into their own file (imported from commit 91a786849bfa30dcacecef6b8339d8f1a9365156) --- zephyr/lib/response.py | 14 ++++++++++++++ zephyr/views.py | 13 +------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 zephyr/lib/response.py diff --git a/zephyr/lib/response.py b/zephyr/lib/response.py new file mode 100644 index 0000000000..49aa0a6b6a --- /dev/null +++ b/zephyr/lib/response.py @@ -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) diff --git a/zephyr/views.py b/zephyr/views.py index 4b3667a5a9..3d1e3bd3df 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -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)