[Python-modules-commits] [python-django-jsonfield] 03/05: Import python-django-jsonfield_0.9.19.orig.tar.gz
Brian May
bam at moszumanska.debian.org
Wed Apr 6 03:57:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
bam pushed a commit to branch master
in repository python-django-jsonfield.
commit a586c9bf55bb02459675bbd98c47412eff1d01bf
Author: Brian May <bam at debian.org>
Date: Wed Apr 6 13:46:12 2016 +1000
Import python-django-jsonfield_0.9.19.orig.tar.gz
---
PKG-INFO | 23 ++++++++++++++++++++---
README.rst | 21 +++++++++++++++++++--
django_jsonfield.egg-info/PKG-INFO | 23 ++++++++++++++++++++---
jsonfield/VERSION | 2 +-
jsonfield/fields.py | 21 +++++++++++++++------
jsonfield/utils.py | 12 ++++++++++++
6 files changed, 87 insertions(+), 15 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 4c30111..a7a706d 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: django-jsonfield
-Version: 0.9.15
+Version: 0.9.19
Summary: JSONField for django models
Home-page: http://bitbucket.org/schinckel/django-jsonfield/
Author: Matthew Schinckel
@@ -9,8 +9,7 @@ License: UNKNOWN
Description: django-jsonfield
===================
- .. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/status.png
- .. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/coverage_status.png
+ .. image:: https://codeship.com/projects/2e1a3d30-7db7-0132-629f-4abd151a3721/status?branch=default
I had a serious need for a JSON field for django. There were a couple out
there, but none packaged up nicely on bitbucket/github that were usable
@@ -60,6 +59,24 @@ Description: django-jsonfield
History
----------
+ 0.9.19
+ ~~~~~~
+ Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
+ the `json.loads()` calls when loading data that is a string.
+
+ You may also set this as a global value in settings.JSONFIELD_DECODER_KWARGS.
+
+ A new dict is created for each field: so if this value is altered after field definition, it shouldn't
+ affect already attached fields.
+
+ 0.9.16
+ ~~~~~~
+ Allow passing an argument of `encoder_class` to a field, which will result in that object (or
+ the object located at that path, for instance `core.utils.JSONEncoder`) being used as the `cls`
+ argument when serializing objects.
+
+ You may also set this as a global value in settings.JSONFIELD_ENCODER_CLASS
+
0.9.15
~~~~~~
Bump version number to get around uploading issues.
diff --git a/README.rst b/README.rst
index 97b4c60..35d4fcb 100644
--- a/README.rst
+++ b/README.rst
@@ -1,8 +1,7 @@
django-jsonfield
===================
-.. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/status.png
-.. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/coverage_status.png
+.. image:: https://codeship.com/projects/2e1a3d30-7db7-0132-629f-4abd151a3721/status?branch=default
I had a serious need for a JSON field for django. There were a couple out
there, but none packaged up nicely on bitbucket/github that were usable
@@ -52,6 +51,24 @@ This allows you to convert a python data structure into JSON within a template::
History
----------
+0.9.19
+~~~~~~
+Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
+the `json.loads()` calls when loading data that is a string.
+
+You may also set this as a global value in settings.JSONFIELD_DECODER_KWARGS.
+
+A new dict is created for each field: so if this value is altered after field definition, it shouldn't
+affect already attached fields.
+
+0.9.16
+~~~~~~
+Allow passing an argument of `encoder_class` to a field, which will result in that object (or
+the object located at that path, for instance `core.utils.JSONEncoder`) being used as the `cls`
+argument when serializing objects.
+
+You may also set this as a global value in settings.JSONFIELD_ENCODER_CLASS
+
0.9.15
~~~~~~
Bump version number to get around uploading issues.
diff --git a/django_jsonfield.egg-info/PKG-INFO b/django_jsonfield.egg-info/PKG-INFO
index 4c30111..a7a706d 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.15
+Version: 0.9.19
Summary: JSONField for django models
Home-page: http://bitbucket.org/schinckel/django-jsonfield/
Author: Matthew Schinckel
@@ -9,8 +9,7 @@ License: UNKNOWN
Description: django-jsonfield
===================
- .. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/status.png
- .. image:: https://drone.io/bitbucket.org/schinckel/django-jsonfield/files/coverage_status.png
+ .. image:: https://codeship.com/projects/2e1a3d30-7db7-0132-629f-4abd151a3721/status?branch=default
I had a serious need for a JSON field for django. There were a couple out
there, but none packaged up nicely on bitbucket/github that were usable
@@ -60,6 +59,24 @@ Description: django-jsonfield
History
----------
+ 0.9.19
+ ~~~~~~
+ Allow passing `decoder_kwargs` as an argument to a field. This dict will be passed as kwargs to
+ the `json.loads()` calls when loading data that is a string.
+
+ You may also set this as a global value in settings.JSONFIELD_DECODER_KWARGS.
+
+ A new dict is created for each field: so if this value is altered after field definition, it shouldn't
+ affect already attached fields.
+
+ 0.9.16
+ ~~~~~~
+ Allow passing an argument of `encoder_class` to a field, which will result in that object (or
+ the object located at that path, for instance `core.utils.JSONEncoder`) being used as the `cls`
+ argument when serializing objects.
+
+ You may also set this as a global value in settings.JSONFIELD_ENCODER_CLASS
+
0.9.15
~~~~~~
Bump version number to get around uploading issues.
diff --git a/jsonfield/VERSION b/jsonfield/VERSION
index 5d11b14..f752268 100644
--- a/jsonfield/VERSION
+++ b/jsonfield/VERSION
@@ -1 +1 @@
-0.9.15
+0.9.19
diff --git a/jsonfield/fields.py b/jsonfield/fields.py
index a4487c7..fa78689 100644
--- a/jsonfield/fields.py
+++ b/jsonfield/fields.py
@@ -11,7 +11,7 @@ from django.core.cache import cache
from decimal import Decimal
import datetime
-from .utils import default
+from .utils import default, _resolve_object_path
from .widgets import JSONWidget
from .forms import JSONFormField
from jsonfield import __version__
@@ -35,8 +35,15 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
if not kwargs.get('null', False):
kwargs['default'] = kwargs.get('default', dict)
self.encoder_kwargs = {
- 'indent': kwargs.pop('indent', getattr(settings, 'JSONFIELD_INDENT', None))
+ 'indent': kwargs.pop('indent', getattr(settings, 'JSONFIELD_INDENT', None)),
}
+ # This can be an object (probably a class), or a path which can be imported, resulting
+ # in an object.
+ encoder_class = kwargs.pop('encoder_class', getattr(settings, 'JSONFIELD_ENCODER_CLASS', None))
+ if encoder_class:
+ self.encoder_kwargs['cls'] = _resolve_object_path(encoder_class)
+
+ self.decoder_kwargs = dict(kwargs.pop('decoder_kwargs', getattr(settings, 'JSONFIELD_DECODER_KWARGS', {})))
super(JSONField, self).__init__(*args, **kwargs)
self.validate(self.get_default(), None)
@@ -62,8 +69,8 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
if callable(default):
default = default()
if isinstance(default, six.string_types):
- return json.loads(default)
- return json.loads(json.dumps(default))
+ return json.loads(default, **self.decoder_kwargs)
+ return json.loads(json.dumps(default, **self.encoder_kwargs), **self.decoder_kwargs)
return super(JSONField, self).get_default()
def get_internal_type(self):
@@ -77,6 +84,8 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
return 'text'
if connection.vendor == 'mysql':
return 'longtext'
+ if connection.vendor == 'oracle':
+ return 'long'
return 'text'
def to_python(self, value):
@@ -87,7 +96,7 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
if self.blank:
return ""
try:
- value = json.loads(value)
+ value = json.loads(value, **self.decoder_kwargs)
except ValueError:
msg = self.error_messages['invalid'] % value
raise ValidationError(msg)
@@ -102,7 +111,7 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):
if not self.null and self.blank:
return ""
return None
- return json.dumps(value, default=default, **self.encoder_kwargs)
+ return json.dumps(value, **self.encoder_kwargs)
def get_prep_lookup(self, lookup_type, value):
if lookup_type in ["exact", "iexact"]:
diff --git a/jsonfield/utils.py b/jsonfield/utils.py
index a6b1c6e..fce90b2 100644
--- a/jsonfield/utils.py
+++ b/jsonfield/utils.py
@@ -3,6 +3,7 @@ from decimal import Decimal
from django.core.serializers.json import DjangoJSONEncoder
+import six
class TZAwareJSONEncoder(DjangoJSONEncoder):
def default(self, obj):
@@ -30,3 +31,14 @@ def default(o):
return list(o)
raise TypeError(repr(o) + " is not JSON serializable")
+
+
+def _resolve_object_path(dotted_name):
+ if isinstance(dotted_name, six.string_types):
+ path = dotted_name.split('.')
+ module = __import__(dotted_name.rsplit('.', 1)[0])
+ for item in path[1:-1]:
+ module = getattr(module, item)
+ return getattr(module, path[-1])
+
+ return dotted_name
--
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