python-oxdjango/oxdjango/shortcuts.py
2010-01-26 19:25:01 +05:30

20 lines
665 B
Python

# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.http import HttpResponse
try:
import simplejson
except ImportError:
from django.utils import simplejson
from django.conf import settings
def render_to_json_response(dictionary, content_type="text/json", status=200):
indent=None
if settings.DEBUG:
content_type = "text/javascript"
indent = 2
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)