Permalink
Browse files

need to really support python 2 json

  • Loading branch information...
igorkramaric committed Aug 23, 2017
1 parent 7bfdf25 commit 4f318eecf08089278f0026f846c27311121cc29a
Showing with 8 additions and 8 deletions.
  1. +3 −3 jsonate/fields.py
  2. +2 −2 jsonate/widgets.py
  3. +3 −3 test_project/test_app/tests.py
View
@@ -1,4 +1,4 @@
from builtins import str
from past.builtins import basestring
try:
import json
except ImportError:
@@ -20,7 +20,7 @@ def _deserialize(self, value):
return None
try:
if isinstance(value, str):
if isinstance(value, basestring):
return json.loads(value)
except ValueError:
pass
@@ -37,7 +37,7 @@ def get_db_prep_value(self, value, connection, prepared=False):
if value == "":
return None
if not isinstance(value, str):
if not isinstance(value, basestring):
value = jsonate(value)
return value
View
@@ -1,4 +1,4 @@
from builtins import str
from past.builtins import basestring
try:
import json
except ImportError:
@@ -12,6 +12,6 @@
class JsonateWidget(forms.Textarea):
def render(self, name, value, attrs=None):
if not isinstance(value, str):
if not isinstance(value, basestring):
value = jsonate(value, indent=2)
return super(JsonateWidget, self).render(name, value, attrs)
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from builtins import range
from builtins import str
from past.builtins import basestring
from builtins import object
from os import unlink, rmdir
@@ -49,7 +49,7 @@ def tearDown(self):
def assertJsonEqual(self, obj1, obj2, *args, **kwargs):
obj1 = json.loads(obj1)
if isinstance(obj2, str):
if isinstance(obj2, basestring):
obj2 = json.loads(obj2)
self.assertEqual(obj1, obj2, *args, **kwargs)
@@ -59,7 +59,7 @@ def assertJSONField(to_write):
obj.some_json_data = to_write
obj.save()
expected = json.loads(to_write) if isinstance(to_write, str) else to_write
expected = json.loads(to_write) if isinstance(to_write, basestring) else to_write
self.assertEqual(
MyModelWithJsonateField.objects.first().some_json_data,

0 comments on commit 4f318ee

Please sign in to comment.