Merge pull request #202 from patrick91/feature/up-django

Remove support to django 1.6 and 1.7
This commit is contained in:
Syrus Akbary 2017-06-24 15:43:35 -07:00 committed by GitHub
commit 7eb4106e7c
7 changed files with 12 additions and 71 deletions

View File

@ -49,10 +49,6 @@ env:
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- python: '2.7'
env: TEST_TYPE=build DJANGO_VERSION=1.6
- python: '2.7'
env: TEST_TYPE=build DJANGO_VERSION=1.7
- python: '2.7' - python: '2.7'
env: TEST_TYPE=build DJANGO_VERSION=1.8 env: TEST_TYPE=build DJANGO_VERSION=1.8
- python: '2.7' - python: '2.7'

View File

@ -1,27 +1,10 @@
from django.db import models
class MissingType(object): class MissingType(object):
pass pass
try: try:
DurationField = models.DurationField # Postgres fields are only available in Django with psycopg2 installed
UUIDField = models.UUIDField # and we cannot have psycopg2 on PyPy
except AttributeError:
# Improved compatibility for Django 1.6
DurationField = MissingType
UUIDField = MissingType
try:
from django.db.models.related import RelatedObject
except:
# Improved compatibility for Django 1.6
RelatedObject = MissingType
try:
# Postgres fields are only available in Django 1.8+
from django.contrib.postgres.fields import ArrayField, HStoreField, RangeField from django.contrib.postgres.fields import ArrayField, HStoreField, RangeField
except ImportError: except ImportError:
ArrayField, HStoreField, JSONField, RangeField = (MissingType, ) * 4 ArrayField, HStoreField, JSONField, RangeField = (MissingType, ) * 4

View File

@ -9,8 +9,7 @@ from graphene.types.json import JSONString
from graphene.utils.str_converters import to_camel_case, to_const from graphene.utils.str_converters import to_camel_case, to_const
from graphql import assert_valid_name from graphql import assert_valid_name
from .compat import (ArrayField, HStoreField, JSONField, RangeField, from .compat import ArrayField, HStoreField, JSONField, RangeField
RelatedObject, UUIDField, DurationField)
from .fields import get_connection_field, DjangoListField from .fields import get_connection_field, DjangoListField
from .utils import get_related_model, import_single_dispatch from .utils import get_related_model, import_single_dispatch
@ -80,7 +79,7 @@ def convert_field_to_string(field, registry=None):
@convert_django_field.register(models.AutoField) @convert_django_field.register(models.AutoField)
@convert_django_field.register(UUIDField) @convert_django_field.register(models.UUIDField)
def convert_field_to_id(field, registry=None): def convert_field_to_id(field, registry=None):
return ID(description=field.help_text, required=not field.null) return ID(description=field.help_text, required=not field.null)
@ -106,7 +105,7 @@ def convert_field_to_nullboolean(field, registry=None):
@convert_django_field.register(models.DecimalField) @convert_django_field.register(models.DecimalField)
@convert_django_field.register(models.FloatField) @convert_django_field.register(models.FloatField)
@convert_django_field.register(DurationField) @convert_django_field.register(models.DurationField)
def convert_field_to_float(field, registry=None): def convert_field_to_float(field, registry=None):
return Float(description=field.help_text, required=not field.null) return Float(description=field.help_text, required=not field.null)
@ -157,26 +156,6 @@ def convert_field_to_list_or_connection(field, registry=None):
return Dynamic(dynamic_type) return Dynamic(dynamic_type)
# For Django 1.6
@convert_django_field.register(RelatedObject)
def convert_relatedfield_to_djangomodel(field, registry=None):
model = field.model
def dynamic_type():
_type = registry.get_type_for_model(model)
if not _type:
return
if isinstance(field.field, models.OneToOneField):
return Field(_type)
if is_node(_type):
return get_connection_field(_type)
return DjangoListField(_type)
return Dynamic(dynamic_type)
@convert_django_field.register(models.OneToOneField) @convert_django_field.register(models.OneToOneField)
@convert_django_field.register(models.ForeignKey) @convert_django_field.register(models.ForeignKey)
def convert_field_to_djangomodel(field, registry=None): def convert_field_to_djangomodel(field, registry=None):

View File

@ -3,7 +3,6 @@ import pytest
import graphene import graphene
from graphene.relay import Node from graphene.relay import Node
from graphene_django import DjangoConnectionField, DjangoObjectType from graphene_django import DjangoConnectionField, DjangoObjectType
from graphene_django.utils import DJANGO_FILTER_INSTALLED
from ...tests.models import Reporter from ...tests.models import Reporter
from ..middleware import DjangoDebugMiddleware from ..middleware import DjangoDebugMiddleware
@ -167,8 +166,6 @@ def test_should_query_connection():
assert result.data['__debug']['sql'][1]['rawSql'] == query assert result.data['__debug']['sql'][1]['rawSql'] == query
@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
reason="requires django-filter")
def test_should_query_connectionfilter(): def test_should_query_connectionfilter():
from ...filter import DjangoFilterConnectionField from ...filter import DjangoFilterConnectionField

View File

@ -8,8 +8,7 @@ from graphene.relay import ConnectionField, Node
from graphene.types.datetime import DateTime, Time from graphene.types.datetime import DateTime, Time
from graphene.types.json import JSONString from graphene.types.json import JSONString
from ..compat import (ArrayField, HStoreField, JSONField, MissingType, from ..compat import JSONField, ArrayField, HStoreField, RangeField, MissingType
RangeField, UUIDField, DurationField)
from ..converter import convert_django_field, convert_django_field_with_choices from ..converter import convert_django_field, convert_django_field_with_choices
from ..registry import Registry from ..registry import Registry
from ..types import DjangoObjectType from ..types import DjangoObjectType
@ -84,14 +83,12 @@ def test_should_auto_convert_id():
assert_conversion(models.AutoField, graphene.ID, primary_key=True) assert_conversion(models.AutoField, graphene.ID, primary_key=True)
@pytest.mark.skipif(UUIDField == MissingType, reason="requires Django UUIDField")
def test_should_auto_convert_id(): def test_should_auto_convert_id():
assert_conversion(UUIDField, graphene.ID) assert_conversion(models.UUIDField, graphene.ID)
@pytest.mark.skipif(DurationField == MissingType, reason="requires Django DurationField")
def test_should_auto_convert_duration(): def test_should_auto_convert_duration():
assert_conversion(DurationField, graphene.Float) assert_conversion(models.DurationField, graphene.Float)
def test_should_positive_integer_convert_int(): def test_should_positive_integer_convert_int():

View File

@ -3,8 +3,6 @@ import inspect
from django.db import models from django.db import models
from django.db.models.manager import Manager from django.db.models.manager import Manager
from .compat import RelatedObject
# from graphene.utils import LazyList # from graphene.utils import LazyList
@ -13,12 +11,8 @@ class LazyList(object):
pass pass
try:
import django_filters # noqa import django_filters # noqa
DJANGO_FILTER_INSTALLED = True DJANGO_FILTER_INSTALLED = True
except (ImportError, AttributeError):
# AtributeError raised if DjangoFilters installed with a incompatible Django Version
DJANGO_FILTER_INSTALLED = False
def get_reverse_fields(model, local_field_names): def get_reverse_fields(model, local_field_names):
@ -30,12 +24,7 @@ def get_reverse_fields(model, local_field_names):
# Django =>1.9 uses 'rel', django <1.9 uses 'related' # Django =>1.9 uses 'rel', django <1.9 uses 'related'
related = getattr(attr, 'rel', None) or \ related = getattr(attr, 'rel', None) or \
getattr(attr, 'related', None) getattr(attr, 'related', None)
if isinstance(related, RelatedObject): if isinstance(related, models.ManyToOneRel):
# Hack for making it compatible with Django 1.6
new_related = RelatedObject(related.parent_model, related.model, related.field)
new_related.name = name
yield (name, new_related)
elif isinstance(related, models.ManyToOneRel):
yield (name, related) yield (name, related)
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical: elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
yield (name, related) yield (name, related)

View File

@ -44,7 +44,7 @@ setup(
install_requires=[ install_requires=[
'six>=1.10.0', 'six>=1.10.0',
'graphene>=1.4', 'graphene>=1.4',
'Django>=1.6.0', 'Django>=1.8.0',
'iso8601', 'iso8601',
'singledispatch>=3.4.0.3', 'singledispatch>=3.4.0.3',
], ],