[Python-modules-commits] [python-django-jsonfield] 02/06: Import python-django-jsonfield_1.0.0.orig.tar.gz

Raphaël Hertzog hertzog at moszumanska.debian.org
Wed Jun 22 23:08:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

hertzog pushed a commit to branch master
in repository python-django-jsonfield.

commit e1ff08a7e797638e4818aa679ece5a7bfc355048
Author: Raphaël Hertzog <hertzog at debian.org>
Date:   Wed Jun 22 20:17:47 2016 +0200

    Import python-django-jsonfield_1.0.0.orig.tar.gz
---
 PKG-INFO                           | 23 ++++++++++++++----
 README.rst                         | 21 ++++++++++++----
 django_jsonfield.egg-info/PKG-INFO | 23 ++++++++++++++----
 jsonfield/VERSION                  |  2 +-
 jsonfield/__init__.py              | 11 +++++----
 jsonfield/fields.py                | 49 ++++++++------------------------------
 jsonfield/tests/test_fields.py     | 48 ++++++++++++++++++-------------------
 jsonfield/utils.py                 |  2 +-
 jsonfield/widgets.py               |  3 ++-
 9 files changed, 96 insertions(+), 86 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index a7a706d..55f26fc 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-jsonfield
-Version: 0.9.19
+Version: 1.0.0
 Summary: JSONField for django models
 Home-page: http://bitbucket.org/schinckel/django-jsonfield/
 Author: Matthew Schinckel
@@ -28,9 +28,10 @@ Description: django-jsonfield
             class MyModel(models.Model):
                 the_json = jsonfield.JSONField()
         
-        Now, it will validate the JSON on entry, and store it as a string in the
-        database.  When you instantiate/fetch the object, it will be turned back
-        into a python list/dict/string.
+        You can assign any JSON-encodable object to this field. It will be
+        JSON-encoded before being stored in the database as a text value and it
+        will be turned back into a python list/dict/string upon retrieval from the
+        database.
         
         There is also a ``TypedJSONField``, that allows you to define data types that must be included within each object in the array. More documentation to follow.
         
@@ -41,7 +42,11 @@ Description: django-jsonfield
         If no ``default`` is provided, and ``null=True`` is not passed in to the
         field constructor, then a default of ``{}`` will be used.
         
-        There are also a couple of other bits and bobs:
+        
+        Supported django versions
+        -------------------------
+        
+        All versions of Django from 1.8 onwards are tested, however, if you are using Postgres, I highly recommend that you consider using the ``django.contrib.postgres`` module's ``JSONField`` instead.
         
         Extras
         ------
@@ -59,6 +64,14 @@ Description: django-jsonfield
         History
         ----------
         
+        1.0.0
+        ~~~~~
+        
+        Add support for Django 1.8 and 1.9 (without warnings). Remove support for Django < 1.8
+        as none of those releases are supported upstream anyway.
+        
+        With this version, ``JSONField`` no longer decodes assigned string values as JSON. Instead it assumes that any value that you assign is the decoded value which will be JSON-encoded before storage in the database. This explains the bump to version 1.0 as it's a backwards incompatible change.
+        
         0.9.19
         ~~~~~~
         Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
diff --git a/README.rst b/README.rst
index 35d4fcb..34a58ac 100644
--- a/README.rst
+++ b/README.rst
@@ -20,9 +20,10 @@ To use, just install the package, and then use the field::
     class MyModel(models.Model):
         the_json = jsonfield.JSONField()
 
-Now, it will validate the JSON on entry, and store it as a string in the
-database.  When you instantiate/fetch the object, it will be turned back
-into a python list/dict/string.
+You can assign any JSON-encodable object to this field. It will be
+JSON-encoded before being stored in the database as a text value and it
+will be turned back into a python list/dict/string upon retrieval from the
+database.
 
 There is also a ``TypedJSONField``, that allows you to define data types that must be included within each object in the array. More documentation to follow.
 
@@ -33,7 +34,11 @@ Notes
 If no ``default`` is provided, and ``null=True`` is not passed in to the
 field constructor, then a default of ``{}`` will be used.
 
-There are also a couple of other bits and bobs:
+
+Supported django versions
+-------------------------
+
+All versions of Django from 1.8 onwards are tested, however, if you are using Postgres, I highly recommend that you consider using the ``django.contrib.postgres`` module's ``JSONField`` instead.
 
 Extras
 ------
@@ -51,6 +56,14 @@ This allows you to convert a python data structure into JSON within a template::
 History
 ----------
 
+1.0.0
+~~~~~
+
+Add support for Django 1.8 and 1.9 (without warnings). Remove support for Django < 1.8
+as none of those releases are supported upstream anyway.
+
+With this version, ``JSONField`` no longer decodes assigned string values as JSON. Instead it assumes that any value that you assign is the decoded value which will be JSON-encoded before storage in the database. This explains the bump to version 1.0 as it's a backwards incompatible change.
+
 0.9.19
 ~~~~~~
 Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
diff --git a/django_jsonfield.egg-info/PKG-INFO b/django_jsonfield.egg-info/PKG-INFO
index a7a706d..55f26fc 100644
--- a/django_jsonfield.egg-info/PKG-INFO
+++ b/django_jsonfield.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-jsonfield
-Version: 0.9.19
+Version: 1.0.0
 Summary: JSONField for django models
 Home-page: http://bitbucket.org/schinckel/django-jsonfield/
 Author: Matthew Schinckel
@@ -28,9 +28,10 @@ Description: django-jsonfield
             class MyModel(models.Model):
                 the_json = jsonfield.JSONField()
         
-        Now, it will validate the JSON on entry, and store it as a string in the
-        database.  When you instantiate/fetch the object, it will be turned back
-        into a python list/dict/string.
+        You can assign any JSON-encodable object to this field. It will be
+        JSON-encoded before being stored in the database as a text value and it
+        will be turned back into a python list/dict/string upon retrieval from the
+        database.
         
         There is also a ``TypedJSONField``, that allows you to define data types that must be included within each object in the array. More documentation to follow.
         
@@ -41,7 +42,11 @@ Description: django-jsonfield
         If no ``default`` is provided, and ``null=True`` is not passed in to the
         field constructor, then a default of ``{}`` will be used.
         
-        There are also a couple of other bits and bobs:
+        
+        Supported django versions
+        -------------------------
+        
+        All versions of Django from 1.8 onwards are tested, however, if you are using Postgres, I highly recommend that you consider using the ``django.contrib.postgres`` module's ``JSONField`` instead.
         
         Extras
         ------
@@ -59,6 +64,14 @@ Description: django-jsonfield
         History
         ----------
         
+        1.0.0
+        ~~~~~
+        
+        Add support for Django 1.8 and 1.9 (without warnings). Remove support for Django < 1.8
+        as none of those releases are supported upstream anyway.
+        
+        With this version, ``JSONField`` no longer decodes assigned string values as JSON. Instead it assumes that any value that you assign is the decoded value which will be JSON-encoded before storage in the database. This explains the bump to version 1.0 as it's a backwards incompatible change.
+        
         0.9.19
         ~~~~~~
         Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
diff --git a/jsonfield/VERSION b/jsonfield/VERSION
index f752268..3eefcb9 100644
--- a/jsonfield/VERSION
+++ b/jsonfield/VERSION
@@ -1 +1 @@
-0.9.19
+1.0.0
diff --git a/jsonfield/__init__.py b/jsonfield/__init__.py
index 10b91dc..75b3f78 100644
--- a/jsonfield/__init__.py
+++ b/jsonfield/__init__.py
@@ -1,7 +1,8 @@
 import os
-__version__ = open(os.path.join(os.path.dirname(__file__), 'VERSION')).read().strip()
 
-try:
-    from .fields import JSONField  # NOQA
-except ImportError:
-    pass
+from .fields import JSONField
+
+__all__ = ('JSONField',)
+
+with open(os.path.join(os.path.dirname(__file__), 'VERSION')) as fp:
+    __version__ = fp.read().strip()
diff --git a/jsonfield/fields.py b/jsonfield/fields.py
index fa78689..551b6eb 100644
--- a/jsonfield/fields.py
+++ b/jsonfield/fields.py
@@ -3,26 +3,16 @@ import json
 
 from django.core.exceptions import ValidationError
 from django.conf import settings
-from django.db import models, DatabaseError, transaction
+from django.db import models
 from django.utils.translation import ugettext_lazy as _
 from django.utils import six
-from django.core.cache import cache
 
-from decimal import Decimal
-import datetime
-
-from .utils import default, _resolve_object_path
+from .utils import _resolve_object_path
 from .widgets import JSONWidget
 from .forms import JSONFormField
-from jsonfield import __version__
-
-DB_TYPE_CACHE_KEY = (
-    'django-jsonfield:db-type:%s' % __version__ +
-    '%(ENGINE)s:%(HOST)s:%(PORT)s:%(NAME)s'
-)
 
 
-class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
+class JSONField(models.Field):
     """
     A field that will ensure the data entered into it is valid JSON.
     """
@@ -88,20 +78,11 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
             return 'long'
         return 'text'
 
-    def to_python(self, value):
-        if isinstance(value, six.string_types):
-            if value == "":
-                if self.null:
-                    return None
-                if self.blank:
-                    return ""
-            try:
-                value = json.loads(value, **self.decoder_kwargs)
-            except ValueError:
-                msg = self.error_messages['invalid'] % value
-                raise ValidationError(msg)
-        # TODO: Look for date/time/datetime objects within the structure?
-        return value
+    def from_db_value(self, value, expression, connection, context):
+        if value is None:
+            return None
+        return json.loads(value, **self.decoder_kwargs)
+
 
     def get_db_prep_value(self, value, connection=None, prepared=None):
         return self.get_prep_value(value)
@@ -114,11 +95,7 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
         return json.dumps(value, **self.encoder_kwargs)
 
     def get_prep_lookup(self, lookup_type, value):
-        if lookup_type in ["exact", "iexact"]:
-            return self.to_python(self.get_prep_value(value))
-        if lookup_type == "in":
-            return [self.to_python(self.get_prep_value(v)) for v in value]
-        if lookup_type == "isnull":
+        if lookup_type in ["exact", "iexact", "in", "isnull"]:
             return value
         if lookup_type in ["contains", "icontains"]:
             if isinstance(value, (list, tuple)):
@@ -129,7 +106,7 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
                 return self.get_prep_value(value)[1:-1].replace(', ', r'%')
             if isinstance(value, dict):
                 return self.get_prep_value(value)[1:-1]
-            return self.to_python(self.get_prep_value(value))
+            return self.get_prep_value(value)
         raise TypeError('Lookup type %r not supported' % lookup_type)
 
     def value_to_string(self, obj):
@@ -173,9 +150,3 @@ class TypedJSONField(JSONField):
             else:
                 v(value)
 
-try:
-    from south.modelsinspector import add_introspection_rules
-    add_introspection_rules([], ['^jsonfield\.fields\.JSONField'])
-    add_introspection_rules([], ['^jsonfield\.fields\.TypedJSONField'])
-except ImportError:
-    pass
diff --git a/jsonfield/tests/test_fields.py b/jsonfield/tests/test_fields.py
index ec779a7..b3d1404 100644
--- a/jsonfield/tests/test_fields.py
+++ b/jsonfield/tests/test_fields.py
@@ -1,6 +1,3 @@
-#:coding=utf-8:
-import unittest
-
 from django.test import TestCase as DjangoTestCase
 from django.utils.encoding import force_text
 from django import forms
@@ -11,21 +8,21 @@ from jsonfield.fields import JSONField
 
 class JSONFieldTest(DjangoTestCase):
     def test_json_field(self):
-        obj = JSONFieldTestModel(json='''{
-            "spam": "eggs"
-        }''')
+        obj = JSONFieldTestModel(json={'spam': 'eggs'})
         self.assertEqual(obj.json, {'spam': 'eggs'})
 
     def test_json_field_empty(self):
         obj = JSONFieldTestModel(json='')
+        self.assertEqual(obj.json, '')
+
+    def test_json_field_null(self):
+        obj = JSONFieldTestModel(json=None)
         self.assertEqual(obj.json, None)
 
     def test_json_field_save(self):
         JSONFieldTestModel.objects.create(
             id=10,
-            json='''{
-                "spam": "eggs"
-            }''',
+            json={'spam': 'eggs'},
         )
         obj2 = JSONFieldTestModel.objects.get(id=10)
         self.assertEqual(obj2.json, {'spam': 'eggs'})
@@ -33,6 +30,11 @@ class JSONFieldTest(DjangoTestCase):
     def test_json_field_save_empty(self):
         JSONFieldTestModel.objects.create(id=10, json='')
         obj2 = JSONFieldTestModel.objects.get(id=10)
+        self.assertEqual(obj2.json, '')
+
+    def test_json_field_save_null(self):
+        JSONFieldTestModel.objects.create(id=10, json=None)
+        obj2 = JSONFieldTestModel.objects.get(id=10)
         self.assertEqual(obj2.json, None)
 
     def test_db_prep_save(self):
@@ -53,12 +55,20 @@ class JSONFieldTest(DjangoTestCase):
     def test_formfield_clean_blank(self):
         field = JSONField("test")
         formfield = field.formfield()
-        self.assertRaisesMessage(forms.ValidationError, force_text(formfield.error_messages['required']), formfield.clean, value='')
+        self.assertRaisesMessage(
+            forms.ValidationError,
+            force_text(formfield.error_messages['required']),
+            formfield.clean,
+            value='')
 
     def test_formfield_clean_none(self):
         field = JSONField("test")
         formfield = field.formfield()
-        self.assertRaisesMessage(forms.ValidationError, force_text(formfield.error_messages['required']), formfield.clean, value=None)
+        self.assertRaisesMessage(
+            forms.ValidationError,
+            force_text(formfield.error_messages['required']),
+            formfield.clean,
+            value=None)
 
     def test_formfield_null_and_blank_clean_blank(self):
         field = JSONField("test", null=True, blank=True)
@@ -138,24 +148,12 @@ class JSONFieldTest(DjangoTestCase):
         obj1.json['foo'] = 'bar'
         self.assertNotIn('foo', obj2.json)
 
-    def test_invalid_json(self):
-        obj = JSONFieldTestModel()
-        obj.json = '{"foo": 2}'
-        self.assertIn('foo', obj.json)
-        with self.assertRaises(forms.ValidationError):
-            obj.json = '{"foo"}'
-
-    def test_invalid_json_default(self):
-        with self.assertRaises(ValueError):
-            JSONField('test', default='{"foo"}')
-
     def test_indent(self):
         JSONField('test', indent=2)
 
-    @unittest.expectedFailure
-    def test_string_is_valid_json(self):
+    def test_string_is_not_json_decoded(self):
         JSONFieldTestModel.objects.create(json='"foo"')
-        self.assertEqual('foo', JSONFieldTestModel.objects.get().json)
+        self.assertEqual('"foo"', JSONFieldTestModel.objects.get().json)
 
 
 class SavingModelsTest(DjangoTestCase):
diff --git a/jsonfield/utils.py b/jsonfield/utils.py
index fce90b2..1e597a9 100644
--- a/jsonfield/utils.py
+++ b/jsonfield/utils.py
@@ -2,8 +2,8 @@ import datetime
 from decimal import Decimal
 
 from django.core.serializers.json import DjangoJSONEncoder
+from django.utils import six
 
-import six
 
 class TZAwareJSONEncoder(DjangoJSONEncoder):
     def default(self, obj):
diff --git a/jsonfield/widgets.py b/jsonfield/widgets.py
index 71fe446..c989c1c 100644
--- a/jsonfield/widgets.py
+++ b/jsonfield/widgets.py
@@ -11,7 +11,8 @@ class JSONWidget(forms.Textarea):
         if value is None:
             value = ""
         if not isinstance(value, six.string_types):
-            value = json.dumps(value, indent=2, default=default)
+            value = json.dumps(value, ensure_ascii=False, indent=2,
+                               default=default)
         return super(JSONWidget, self).render(name, value, attrs)
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-jsonfield.git



More information about the Python-modules-commits mailing list