django 1.10 fix (#516)
Fix django packages for 1.10, add docs noting django 1.8+ support.
This commit is contained in:
committed by
Jon Wayne Parrott
parent
f322ef9cdf
commit
a3cbf51bc9
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
Utilities for using OAuth 2.0 in conjunction with
|
Utilities for using OAuth 2.0 in conjunction with
|
||||||
the Django datastore.
|
the Django datastore.
|
||||||
|
|
||||||
|
|
||||||
|
Only Django versions 1.8+ are supported.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import oauth2client
|
import oauth2client
|
||||||
@@ -31,7 +34,7 @@ from oauth2client.client import Storage as BaseStorage
|
|||||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
|
|
||||||
|
|
||||||
class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
class CredentialsField(models.Field):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if 'null' not in kwargs:
|
if 'null' not in kwargs:
|
||||||
@@ -41,6 +44,9 @@ class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
|||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
return 'TextField'
|
return 'TextField'
|
||||||
|
|
||||||
|
def from_db_value(self, value, expression, connection, context):
|
||||||
|
return self.to_python(value)
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
@@ -68,7 +74,7 @@ class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
|||||||
return self.get_prep_value(value)
|
return self.get_prep_value(value)
|
||||||
|
|
||||||
|
|
||||||
class FlowField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
class FlowField(models.Field):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if 'null' not in kwargs:
|
if 'null' not in kwargs:
|
||||||
@@ -78,6 +84,9 @@ class FlowField(six.with_metaclass(models.SubfieldBase, models.Field)):
|
|||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
return 'TextField'
|
return 'TextField'
|
||||||
|
|
||||||
|
def from_db_value(self, value, expression, connection, context):
|
||||||
|
return self.to_python(value)
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ that user credentials are available, and an ``oauth_enabled`` decorator to check
|
|||||||
if the user has authorized, and helper shortcuts to create the authorization
|
if the user has authorized, and helper shortcuts to create the authorization
|
||||||
URL otherwise.
|
URL otherwise.
|
||||||
|
|
||||||
|
Only Django versions 1.8+ are supported.
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|||||||
@@ -74,8 +74,20 @@ class TestCredentialsField(unittest.TestCase):
|
|||||||
self.assertEquals(self.field.get_internal_type(), 'TextField')
|
self.assertEquals(self.field.get_internal_type(), 'TextField')
|
||||||
|
|
||||||
def test_field_unpickled(self):
|
def test_field_unpickled(self):
|
||||||
self.assertTrue(isinstance(self.field.to_python(self.pickle_str),
|
self.assertTrue(
|
||||||
Credentials))
|
isinstance(self.field.to_python(self.pickle_str), Credentials))
|
||||||
|
|
||||||
|
def test_field_already_unpickled(self):
|
||||||
|
self.assertTrue(isinstance(
|
||||||
|
self.field.to_python(self.credentials), Credentials))
|
||||||
|
|
||||||
|
def test_none_field_unpickled(self):
|
||||||
|
self.assertIsNone(self.field.to_python(None))
|
||||||
|
|
||||||
|
def test_from_db_value(self):
|
||||||
|
value = self.field.from_db_value(
|
||||||
|
self.pickle_str, None, None, None)
|
||||||
|
self.assertTrue(isinstance(value, Credentials))
|
||||||
|
|
||||||
def test_field_unpickled_none(self):
|
def test_field_unpickled_none(self):
|
||||||
self.assertEqual(self.field.to_python(None), None)
|
self.assertEqual(self.field.to_python(None), None)
|
||||||
@@ -120,6 +132,18 @@ class TestFlowField(unittest.TestCase):
|
|||||||
python_val = self.field.to_python(self.pickle_str)
|
python_val = self.field.to_python(self.pickle_str)
|
||||||
self.assertTrue(isinstance(python_val, Flow))
|
self.assertTrue(isinstance(python_val, Flow))
|
||||||
|
|
||||||
|
def test_field_already_unpickled(self):
|
||||||
|
self.assertTrue(
|
||||||
|
isinstance(self.field.to_python(self.flow), Flow))
|
||||||
|
|
||||||
|
def test_none_field_unpickled(self):
|
||||||
|
self.assertIsNone(self.field.to_python(None))
|
||||||
|
|
||||||
|
def test_from_db_value(self):
|
||||||
|
python_val = self.field.from_db_value(
|
||||||
|
self.pickle_str, None, None, None)
|
||||||
|
self.assertTrue(isinstance(python_val, Flow))
|
||||||
|
|
||||||
def test_field_pickled(self):
|
def test_field_pickled(self):
|
||||||
prep_value = self.field.get_db_prep_value(self.flow, connection=None)
|
prep_value = self.field.get_db_prep_value(self.flow, connection=None)
|
||||||
self.assertEqual(prep_value, self.pickle_str)
|
self.assertEqual(prep_value, self.pickle_str)
|
||||||
|
|||||||
Reference in New Issue
Block a user