From 3d2e5f5bd680a4e19aa9f4520142b897a5390f4c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 8 Feb 2010 20:34:54 +0530 Subject: [PATCH] use json instead of simplejson --- oxdjango/shortcuts.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/oxdjango/shortcuts.py b/oxdjango/shortcuts.py index 6c95cff..30481ff 100644 --- a/oxdjango/shortcuts.py +++ b/oxdjango/shortcuts.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 - -from django.http import HttpResponse, Http404, HttpResponseNotFound +from django.http import HttpResponse, Http404 try: - import simplejson + import simplejson as json except ImportError: - from django.utils import simplejson + from django.utils import simplejson as json from django.conf import settings class Http404Json(Http404): @@ -18,10 +17,10 @@ def render_to_json_response(dictionary, content_type="text/json", status=200): content_type = "text/javascript" indent = 2 if settings.JSON_DEBUG: - print simplejson.dumps(dictionary, indent=2) + print json.dumps(dictionary, indent=2) if 'status' in dictionary and 'code' in dictionary['status']: status = dictionary['status']['code'] - return HttpResponse(simplejson.dumps(dictionary, indent=indent), + return HttpResponse(json.dumps(dictionary, indent=indent), content_type=content_type, status=status) def get_object_or_404_json(klass, *args, **kwargs): @@ -30,7 +29,7 @@ def get_object_or_404_json(klass, *args, **kwargs): try: return queryset.get(*args, **kwargs) except queryset.model.DoesNotExist: - #FIXME: how to raise exception that will only output given result response = {'status': {'code': 404, - 'text': '%s not found' % queryset.model._meta.object_name}} + 'text': '%s not found' % queryset.model._meta.object_name}} raise Http404Json(response) +