Remove dependency over six
This commit is contained in:
@@ -3,14 +3,21 @@
|
|||||||
with jSignature jQuery plugin
|
with jSignature jQuery plugin
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import six
|
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from .forms import (
|
from .forms import (
|
||||||
JSignatureField as JSignatureFormField,
|
JSignatureField as JSignatureFormField,
|
||||||
JSIGNATURE_EMPTY_VALUES)
|
JSIGNATURE_EMPTY_VALUES,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from django.utils import six
|
||||||
|
string_types = six.string_types
|
||||||
|
except ImportError:
|
||||||
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class JSignatureField(models.Field):
|
class JSignatureField(models.Field):
|
||||||
@@ -39,7 +46,7 @@ class JSignatureField(models.Field):
|
|||||||
def get_prep_value(self, value):
|
def get_prep_value(self, value):
|
||||||
if value in JSIGNATURE_EMPTY_VALUES:
|
if value in JSIGNATURE_EMPTY_VALUES:
|
||||||
return None
|
return None
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, string_types):
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
@@ -49,9 +56,3 @@ class JSignatureField(models.Field):
|
|||||||
defaults = {'form_class': JSignatureFormField}
|
defaults = {'form_class': JSignatureFormField}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
return super(JSignatureField, self).formfield(**defaults)
|
return super(JSignatureField, self).formfield(**defaults)
|
||||||
|
|
||||||
try:
|
|
||||||
from south.modelsinspector import add_introspection_rules
|
|
||||||
add_introspection_rules([], ["jsignature.fields.JSignatureField"])
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
with jSignature jQuery plugin
|
with jSignature jQuery plugin
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import six
|
|
||||||
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.forms.widgets import HiddenInput
|
from django.forms.widgets import HiddenInput
|
||||||
@@ -17,6 +16,13 @@ from jsignature.settings import JSIGNATURE_DEFAULT_CONFIG
|
|||||||
JSIGNATURE_EMPTY_VALUES = validators.EMPTY_VALUES + ('[]', )
|
JSIGNATURE_EMPTY_VALUES = validators.EMPTY_VALUES + ('[]', )
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from django.utils import six
|
||||||
|
string_types = six.string_types
|
||||||
|
except ImportError:
|
||||||
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
class JSignatureWidget(HiddenInput):
|
class JSignatureWidget(HiddenInput):
|
||||||
"""
|
"""
|
||||||
A widget handling a signature capture field with with jSignature
|
A widget handling a signature capture field with with jSignature
|
||||||
@@ -54,7 +60,7 @@ class JSignatureWidget(HiddenInput):
|
|||||||
""" Prepare value before effectively render widget """
|
""" Prepare value before effectively render widget """
|
||||||
if value in JSIGNATURE_EMPTY_VALUES:
|
if value in JSIGNATURE_EMPTY_VALUES:
|
||||||
return "[]"
|
return "[]"
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, string_types):
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
pillow
|
pillow
|
||||||
pyquery
|
pyquery
|
||||||
six
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import six
|
|
||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@@ -7,6 +6,13 @@ from django.core.exceptions import ValidationError
|
|||||||
from jsignature.fields import JSignatureField
|
from jsignature.fields import JSignatureField
|
||||||
from jsignature.forms import JSignatureField as JSignatureFormField
|
from jsignature.forms import JSignatureField as JSignatureFormField
|
||||||
|
|
||||||
|
try:
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
string_types = six.string_types
|
||||||
|
except ImportError:
|
||||||
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
class JSignatureFieldTest(SimpleTestCase):
|
class JSignatureFieldTest(SimpleTestCase):
|
||||||
|
|
||||||
@@ -40,7 +46,7 @@ class JSignatureFieldTest(SimpleTestCase):
|
|||||||
f = JSignatureField()
|
f = JSignatureField()
|
||||||
val = [{"x": [1, 2], "y": [3, 4]}]
|
val = [{"x": [1, 2], "y": [3, 4]}]
|
||||||
val_prep = f.get_prep_value(val)
|
val_prep = f.get_prep_value(val)
|
||||||
self.assertIsInstance(val_prep, six.string_types)
|
self.assertIsInstance(val_prep, string_types)
|
||||||
self.assertEquals(val, json.loads(val_prep))
|
self.assertEquals(val, json.loads(val_prep))
|
||||||
|
|
||||||
def test_get_prep_value_correct_values_json(self):
|
def test_get_prep_value_correct_values_json(self):
|
||||||
@@ -48,7 +54,7 @@ class JSignatureFieldTest(SimpleTestCase):
|
|||||||
val = [{"x": [1, 2], "y": [3, 4]}]
|
val = [{"x": [1, 2], "y": [3, 4]}]
|
||||||
val_str = '[{"x":[1,2], "y":[3,4]}]'
|
val_str = '[{"x":[1,2], "y":[3,4]}]'
|
||||||
val_prep = f.get_prep_value(val_str)
|
val_prep = f.get_prep_value(val_str)
|
||||||
self.assertIsInstance(val_prep, six.string_types)
|
self.assertIsInstance(val_prep, string_types)
|
||||||
self.assertEquals(val, json.loads(val_prep))
|
self.assertEquals(val, json.loads(val_prep))
|
||||||
|
|
||||||
def test_get_prep_value_incorrect_values(self):
|
def test_get_prep_value_incorrect_values(self):
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from pyquery import PyQuery as pq
|
from pyquery import PyQuery as pq
|
||||||
import six
|
|
||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@@ -8,6 +7,13 @@ from django.core.exceptions import ValidationError
|
|||||||
from jsignature.widgets import JSignatureWidget
|
from jsignature.widgets import JSignatureWidget
|
||||||
from jsignature.settings import JSIGNATURE_HEIGHT
|
from jsignature.settings import JSIGNATURE_HEIGHT
|
||||||
|
|
||||||
|
try:
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
string_types = six.string_types
|
||||||
|
except ImportError:
|
||||||
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
class JSignatureWidgetTest(SimpleTestCase):
|
class JSignatureWidgetTest(SimpleTestCase):
|
||||||
|
|
||||||
@@ -49,7 +55,7 @@ class JSignatureWidgetTest(SimpleTestCase):
|
|||||||
w = JSignatureWidget()
|
w = JSignatureWidget()
|
||||||
val = [{"x": [1, 2], "y": [3, 4]}]
|
val = [{"x": [1, 2], "y": [3, 4]}]
|
||||||
val_prep = w.prep_value(val)
|
val_prep = w.prep_value(val)
|
||||||
self.assertIsInstance(val_prep, six.string_types)
|
self.assertIsInstance(val_prep, string_types)
|
||||||
self.assertEquals(val, json.loads(val_prep))
|
self.assertEquals(val, json.loads(val_prep))
|
||||||
|
|
||||||
def test_prep_value_correct_values_json(self):
|
def test_prep_value_correct_values_json(self):
|
||||||
@@ -57,7 +63,7 @@ class JSignatureWidgetTest(SimpleTestCase):
|
|||||||
val = [{"x": [1, 2], "y": [3, 4]}]
|
val = [{"x": [1, 2], "y": [3, 4]}]
|
||||||
val_str = '[{"x":[1,2], "y":[3,4]}]'
|
val_str = '[{"x":[1,2], "y":[3,4]}]'
|
||||||
val_prep = w.prep_value(val_str)
|
val_prep = w.prep_value(val_str)
|
||||||
self.assertIsInstance(val_prep, six.string_types)
|
self.assertIsInstance(val_prep, string_types)
|
||||||
self.assertEquals(val, json.loads(val_prep))
|
self.assertEquals(val, json.loads(val_prep))
|
||||||
|
|
||||||
def test_prep_value_incorrect_values(self):
|
def test_prep_value_incorrect_values(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user