Skip to content

Commit

Permalink
Merge pull request #202 from patrick91/feature/up-django
Browse files Browse the repository at this point in the history
Remove support to django 1.6 and 1.7
  • Loading branch information
syrusakbary committed Jun 24, 2017
2 parents 06f8323 + 82055ac commit 7eb4106
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 71 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ env:
matrix:
fast_finish: true
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'
env: TEST_TYPE=build DJANGO_VERSION=1.8
- python: '2.7'
Expand Down
21 changes: 2 additions & 19 deletions graphene_django/compat.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
from django.db import models


class MissingType(object):
pass


try:
DurationField = models.DurationField
UUIDField = models.UUIDField
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+
# Postgres fields are only available in Django with psycopg2 installed
# and we cannot have psycopg2 on PyPy
from django.contrib.postgres.fields import ArrayField, HStoreField, RangeField
except ImportError:
ArrayField, HStoreField, JSONField, RangeField = (MissingType, ) * 4
Expand Down
27 changes: 3 additions & 24 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from graphene.utils.str_converters import to_camel_case, to_const
from graphql import assert_valid_name

from .compat import (ArrayField, HStoreField, JSONField, RangeField,
RelatedObject, UUIDField, DurationField)
from .compat import ArrayField, HStoreField, JSONField, RangeField
from .fields import get_connection_field, DjangoListField
from .utils import get_related_model, import_single_dispatch

Expand Down Expand Up @@ -80,7 +79,7 @@ def convert_field_to_string(field, registry=None):


@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):
return ID(description=field.help_text, required=not field.null)

Expand All @@ -106,7 +105,7 @@ def convert_field_to_nullboolean(field, registry=None):

@convert_django_field.register(models.DecimalField)
@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):
return Float(description=field.help_text, required=not field.null)

Expand Down Expand Up @@ -157,26 +156,6 @@ def 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.ForeignKey)
def convert_field_to_djangomodel(field, registry=None):
Expand Down
3 changes: 0 additions & 3 deletions graphene_django/debug/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import graphene
from graphene.relay import Node
from graphene_django import DjangoConnectionField, DjangoObjectType
from graphene_django.utils import DJANGO_FILTER_INSTALLED

from ...tests.models import Reporter
from ..middleware import DjangoDebugMiddleware
Expand Down Expand Up @@ -167,8 +166,6 @@ def resolve_all_reporters(self, *args, **kwargs):
assert result.data['__debug']['sql'][1]['rawSql'] == query


@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
reason="requires django-filter")
def test_should_query_connectionfilter():
from ...filter import DjangoFilterConnectionField

Expand Down
9 changes: 3 additions & 6 deletions graphene_django/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from graphene.types.datetime import DateTime, Time
from graphene.types.json import JSONString

from ..compat import (ArrayField, HStoreField, JSONField, MissingType,
RangeField, UUIDField, DurationField)
from ..compat import JSONField, ArrayField, HStoreField, RangeField, MissingType
from ..converter import convert_django_field, convert_django_field_with_choices
from ..registry import Registry
from ..types import DjangoObjectType
Expand Down Expand Up @@ -84,14 +83,12 @@ def test_should_auto_convert_id():
assert_conversion(models.AutoField, graphene.ID, primary_key=True)


@pytest.mark.skipif(UUIDField == MissingType, reason="requires Django UUIDField")
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():
assert_conversion(DurationField, graphene.Float)
assert_conversion(models.DurationField, graphene.Float)


def test_should_positive_integer_convert_int():
Expand Down
17 changes: 3 additions & 14 deletions graphene_django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from django.db import models
from django.db.models.manager import Manager

from .compat import RelatedObject


# from graphene.utils import LazyList

Expand All @@ -13,12 +11,8 @@ class LazyList(object):
pass


try:
import django_filters # noqa
DJANGO_FILTER_INSTALLED = True
except (ImportError, AttributeError):
# AtributeError raised if DjangoFilters installed with a incompatible Django Version
DJANGO_FILTER_INSTALLED = False
import django_filters # noqa
DJANGO_FILTER_INSTALLED = True


def get_reverse_fields(model, local_field_names):
Expand All @@ -30,12 +24,7 @@ def get_reverse_fields(model, local_field_names):
# Django =>1.9 uses 'rel', django <1.9 uses 'related'
related = getattr(attr, 'rel', None) or \
getattr(attr, 'related', None)
if isinstance(related, RelatedObject):
# 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):
if isinstance(related, models.ManyToOneRel):
yield (name, related)
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
yield (name, related)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
install_requires=[
'six>=1.10.0',
'graphene>=1.4',
'Django>=1.6.0',
'Django>=1.8.0',
'iso8601',
'singledispatch>=3.4.0.3',
],
Expand Down

0 comments on commit 7eb4106

Please sign in to comment.