22from django .views .generic import CreateView , DeleteView
33
44from django .http import HttpResponse
5- from django .utils .functional import Promise
6- from django .utils .encoding import force_unicode
75from django .utils import simplejson
86from django .core .urlresolvers import reverse
97
@@ -28,36 +26,6 @@ def delete(self, request, *args, **kwargs):
2826
2927class JSONResponse (HttpResponse ):
3028 """ JSON response class """
31- def __init__ (self ,content = '' ,json_opts = {},mimetype = "application/json" ,* args ,** kwargs ):
32- """
33- This returns a object that we send as json content using
34- samklang.core.encoders.serialize, that is a wrapper to simplejson.dumps
35- method using a custom class to force_unicode for lazy translatons. Put
36- your options to serialize in json_opts, other options are used by
37- response.
38- """
39- if content :
40- content = serialize (content ,** json_opts )
41- else :
42- content = serialize ([],** json_opts )
29+ def __init__ (self ,obj = '' ,json_opts = {},mimetype = "application/json" ,* args ,** kwargs ):
30+ content = simplejson .dumps (obj ,** json_opts )
4331 super (JSONResponse ,self ).__init__ (content ,mimetype ,* args ,** kwargs )
44-
45- def serialize (obj ,* args ,** kwargs ):
46- """ A wrapper for simplejson.dumps with defaults as:
47- ensure_ascii=False
48- cls=LazyJSONEncoder
49-
50- All arguments can be added via kwargs
51- """
52-
53- kwargs ['ensure_ascii' ] = kwargs .get ('ensure_ascii' ,False )
54- kwargs ['cls' ] = kwargs .get ('cls' ,LazyEncoder )
55-
56- return simplejson .dumps (obj ,* args ,** kwargs )
57-
58- class LazyEncoder (simplejson .JSONEncoder ):
59- def default (self , obj ):
60- if isinstance (obj , Promise ):
61- return force_unicode (obj )
62- return super (LazyEncoder , self ).default (obj )
63-
0 commit comments