Add Django 1.10 compatibility
This commit is contained in:
26
.travis.yml
26
.travis.yml
@@ -1,17 +1,16 @@
|
||||
language: python
|
||||
|
||||
python:
|
||||
- 2.6
|
||||
- 2.7
|
||||
- 3.2
|
||||
- 3.3
|
||||
- 3.4
|
||||
- 3.5
|
||||
|
||||
env:
|
||||
- DJANGO_VERSION=1.4 MODULE=jsignature
|
||||
- DJANGO_VERSION=1.5 MODULE=jsignature
|
||||
- DJANGO_VERSION=1.6 MODULE=jsignature.tests
|
||||
- DJANGO_VERSION=1.7 MODULE=jsignature.tests
|
||||
- DJANGO_VERSION=1.8 MODULE=jsignature.tests
|
||||
- DJANGO_VERSION=1.9 MODULE=jsignature.tests
|
||||
- DJANGO_VERSION=1.10 MODULE=jsignature.tests
|
||||
|
||||
install:
|
||||
- pip install -r requirements.txt --use-mirrors
|
||||
@@ -24,19 +23,10 @@ after_success:
|
||||
- pip install coveralls
|
||||
- coveralls
|
||||
|
||||
# We need to exclude old versions of Django for tests with python 3.
|
||||
# We need to exclude old versions of Python for tests with Django >= 1.7.
|
||||
# We need to exclude old versions of Python for tests with Django >= 1.9.
|
||||
matrix:
|
||||
exclude:
|
||||
- python: 3.2
|
||||
env: DJANGO_VERSION=1.4 MODULE=jsignature
|
||||
- python: 3.3
|
||||
env: DJANGO_VERSION=1.4 MODULE=jsignature
|
||||
- python: 3.4
|
||||
env: DJANGO_VERSION=1.4 MODULE=jsignature
|
||||
- python: 3.4
|
||||
env: DJANGO_VERSION=1.5 MODULE=jsignature
|
||||
- python: 3.4
|
||||
env: DJANGO_VERSION=1.6 MODULE=jsignature.tests
|
||||
- python: 2.6
|
||||
env: DJANGO_VERSION=1.7 MODULE=jsignature.tests
|
||||
env: DJANGO_VERSION=1.9 MODULE=jsignature.tests
|
||||
- python: 3.3
|
||||
env: DJANGO_VERSION=1.10 MODULE=jsignature.tests
|
||||
|
||||
@@ -13,7 +13,7 @@ from .forms import (
|
||||
JSIGNATURE_EMPTY_VALUES)
|
||||
|
||||
|
||||
class JSignatureField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
||||
class JSignatureField(models.Field):
|
||||
"""
|
||||
A model field handling a signature captured with jSignature
|
||||
"""
|
||||
@@ -23,10 +23,6 @@ class JSignatureField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
||||
return 'TextField'
|
||||
|
||||
def to_python(self, value):
|
||||
"""
|
||||
Validates that the input can be red as a JSON object. Returns a Python
|
||||
datetime.date object.
|
||||
"""
|
||||
if value in JSIGNATURE_EMPTY_VALUES:
|
||||
return None
|
||||
elif isinstance(value, list):
|
||||
@@ -36,6 +32,14 @@ class JSignatureField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
||||
except ValueError:
|
||||
raise ValidationError('Invalid JSON format.')
|
||||
|
||||
def from_db_value(self, value, expression, connection, context):
|
||||
if value in JSIGNATURE_EMPTY_VALUES:
|
||||
return None
|
||||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
raise ValidationError('Invalid JSON format.')
|
||||
|
||||
def get_prep_value(self, value):
|
||||
if value in JSIGNATURE_EMPTY_VALUES:
|
||||
return None
|
||||
@@ -50,8 +54,3 @@ class JSignatureField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
||||
defaults.update(kwargs)
|
||||
return super(JSignatureField, self).formfield(**defaults)
|
||||
|
||||
try:
|
||||
from south.modelsinspector import add_introspection_rules
|
||||
add_introspection_rules([], ["jsignature.fields.JSignatureField"])
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -31,6 +31,21 @@ class JSignatureFieldTest(SimpleTestCase):
|
||||
val = 'foo'
|
||||
self.assertRaises(ValidationError, f.to_python, val)
|
||||
|
||||
def test_from_db_value_empty(self):
|
||||
f = JSignatureField()
|
||||
self.assertIsNone(f.from_db_value(''))
|
||||
|
||||
def test_from_db_value_correct_value_json(self):
|
||||
f = JSignatureField()
|
||||
val = [{"x": [1, 2], "y": [3, 4]}]
|
||||
val_str = '[{"x":[1,2], "y":[3,4]}]'
|
||||
self.assertEquals(val, f.from_db_value(val_str))
|
||||
|
||||
def test_from_db_value_incorrect_value(self):
|
||||
f = JSignatureField()
|
||||
val = 'foo'
|
||||
self.assertRaises(ValidationError, f.to_python, val)
|
||||
|
||||
def test_get_prep_value_empty(self):
|
||||
f = JSignatureField()
|
||||
for val in ['', [], '[]']:
|
||||
|
||||
Reference in New Issue
Block a user