Commits

Leonardo Santos  committed 371ffd0

Increased to version 0.2.10
Re-fixing tastypie jsonp post serialization error

  • Participants
  • Parent commits 39ede9e

Comments (0)

Files changed (2)

File inoa/tastypie/resources.py

         """
         Generic view wrapper to cache the wrapped view's serialized response.
         """
+        
         check_format = self.create_response(request, None)
         if check_format.content == self._meta.serializer.to_html(None):
             return check_format
                 cache.set(cache_key, serialized_response, self._meta.serialized_cache_timeout)
             else:
                 cache.set(cache_key, serialized_response)
+
         if 'text/javascript' in desired_format:
-            serialized_response.content = unicode(serialized_response.content).replace(u'\u2028', u'\\u2028').replace(u'\u2029', u'\\u2029')
-            serialized_response.content = u'%s(%s)' % (callback, serialized_response.content)
+            content = serialized_response.content
+            try:
+                content = unicode(content)
+            except UnicodeDecodeError:
+                # content is byte string
+                ascii_text = str(content).encode('string_escape')
+                content = unicode(ascii_text)
+            content = content.replace(u'\u2028', u'\\u2028').replace(u'\u2029', u'\\u2029') #TODO (lsantos): check if this line still is needed
+            content = u'%s(%s)' % (callback, content)
+            serialized_response.content = content.decode('string_escape')
 
         return serialized_response
 
 
 setup(
     name='django-inoa',
-    version='0.2.9',
+    version='0.2.10',
     author='Inoa',
     author_email='django@inoa.com.br',
     packages=packages,