mirror of https://github.com/zulip/zulip.git
Move json response functions into their own file
(imported from commit 91a786849bfa30dcacecef6b8339d8f1a9365156)
This commit is contained in:
parent
7bbde14d78
commit
b278db110f
|
@ -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)
|
|
@ -22,6 +22,7 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
from zephyr.decorator import asynchronous
|
from zephyr.decorator import asynchronous
|
||||||
from zephyr.lib.query import last_n
|
from zephyr.lib.query import last_n
|
||||||
from zephyr.lib.avatar import gravatar_hash
|
from zephyr.lib.avatar import gravatar_hash
|
||||||
|
from zephyr.lib.response import json_success, json_error
|
||||||
|
|
||||||
from confirmation.models import Confirmation
|
from confirmation.models import Confirmation
|
||||||
|
|
||||||
|
@ -76,18 +77,6 @@ def authenticated_json_view(view_func):
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
return _wrapped_view_func
|
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):
|
def get_stream(stream_name, realm):
|
||||||
try:
|
try:
|
||||||
return Stream.objects.get(name__iexact=stream_name, realm=realm)
|
return Stream.objects.get(name__iexact=stream_name, realm=realm)
|
||||||
|
|
Loading…
Reference in New Issue