2009-10-11 12:47:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
|
|
|
from django.http import HttpResponse
|
2010-01-22 23:06:33 +00:00
|
|
|
try:
|
|
|
|
import simplejson
|
|
|
|
except ImportError:
|
|
|
|
from django.utils import simplejson
|
2009-10-11 12:47:39 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
2010-01-26 13:55:01 +00:00
|
|
|
def render_to_json_response(dictionary, content_type="text/json", status=200):
|
2009-10-11 12:47:39 +00:00
|
|
|
indent=None
|
|
|
|
if settings.DEBUG:
|
|
|
|
content_type = "text/javascript"
|
|
|
|
indent = 2
|
2010-01-26 13:55:01 +00:00
|
|
|
print simplejson.dumps(dictionary, indent=indent)
|
|
|
|
if 'status' in dictionary and 'code' in dictionary['status']:
|
|
|
|
status = dictionary['status']['code']
|
|
|
|
return HttpResponse(simplejson.dumps(dictionary, indent=indent), content_type=content_type, status=status)
|
2009-10-11 12:47:39 +00:00
|
|
|
|