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