mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 09:57:41 +03:00 
			
		
		
		
	Reverting previous commit following comments by @syrusakbary
This commit is contained in:
		
							parent
							
								
									880807dd2f
								
							
						
					
					
						commit
						93e758dc13
					
				| 
						 | 
				
			
			@ -1,10 +1,9 @@
 | 
			
		|||
from graphene.contrib.django import settings
 | 
			
		||||
from graphene.contrib.django.utils import DJANGO_FILTER_INSTALLED
 | 
			
		||||
 | 
			
		||||
if not settings.GRAPHENE_ENABLE_FILTERING:
 | 
			
		||||
if not DJANGO_FILTER_INSTALLED:
 | 
			
		||||
    raise Exception(
 | 
			
		||||
        "To make use of filtering you configure "
 | 
			
		||||
        "GRAPHENE_ENABLE_FILTERING=True. This will also require "
 | 
			
		||||
        "django-filter be installed"
 | 
			
		||||
        "Use of django filtering requires the django-filter package "
 | 
			
		||||
        "be installed. You can do so using `pip install django-filter`"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
from .fields import DjangoFilterConnectionField
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
import six
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.utils.text import capfirst
 | 
			
		||||
from django_filters import Filter, MultipleChoiceFilter
 | 
			
		||||
from django_filters.filterset import FilterSetMetaclass, FilterSet
 | 
			
		||||
from graphql_relay.node.node import from_global_id
 | 
			
		||||
 | 
			
		||||
from graphene.contrib.django import settings
 | 
			
		||||
from graphene.contrib.django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +25,9 @@ class GlobalIDMultipleChoiceFilter(MultipleChoiceFilter):
 | 
			
		|||
        return super(GlobalIDMultipleChoiceFilter, self).filter(qs, gids)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ORDER_BY_FIELD = getattr(settings, 'GRAPHENE_ORDER_BY_FIELD', 'order_by')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GRAPHENE_FILTER_SET_OVERRIDES = {
 | 
			
		||||
    models.AutoField: {
 | 
			
		||||
        'filter_class': GlobalIDFilter,
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +54,7 @@ class GrapheneFilterSetMetaclass(FilterSetMetaclass):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class GrapheneFilterSetMixin(object):
 | 
			
		||||
    order_by_field = settings.GRAPHENE_ORDER_BY_FIELD
 | 
			
		||||
    order_by_field = ORDER_BY_FIELD
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def filter_for_reverse_field(cls, f, name):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
from graphene.contrib.django import settings
 | 
			
		||||
from .utils import DJANGO_FILTER_INSTALLED
 | 
			
		||||
from ...core.classtypes.objecttype import ObjectTypeOptions
 | 
			
		||||
from ...relay.types import Node
 | 
			
		||||
from ...relay.utils import is_node
 | 
			
		||||
 | 
			
		||||
VALID_ATTRS = ('model', 'only_fields', 'exclude_fields')
 | 
			
		||||
 | 
			
		||||
if settings.GRAPHENE_ENABLE_FILTERING:
 | 
			
		||||
if DJANGO_FILTER_INSTALLED:
 | 
			
		||||
    VALID_ATTRS += ('filter_fields', 'filter_order_by')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +0,0 @@
 | 
			
		|||
from django.conf import settings
 | 
			
		||||
 | 
			
		||||
GRAPHENE_ORDER_BY_FIELD = getattr(settings, 'GRAPHENE_ORDER_BY_FIELD', 'order_by')
 | 
			
		||||
GRAPHENE_ENABLE_FILTERING = getattr(settings, 'GRAPHENE_ENABLE_FILTERING', False)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +0,0 @@
 | 
			
		|||
from graphene.contrib.django import settings
 | 
			
		||||
 | 
			
		||||
# Force filtering for tests
 | 
			
		||||
settings.GRAPHENE_ENABLE_FILTERING = True
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
import pytest
 | 
			
		||||
 | 
			
		||||
from graphene import ObjectType, Schema
 | 
			
		||||
from graphene.contrib.django import settings
 | 
			
		||||
from graphene.contrib.django.utils import DJANGO_FILTER_INSTALLED
 | 
			
		||||
from graphene.relay import NodeField
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -10,7 +10,7 @@ from graphene.contrib.django.forms import GlobalIDFormField, GlobalIDMultipleCho
 | 
			
		|||
from graphene.contrib.django.tests.models import Article, Pet, Reporter
 | 
			
		||||
 | 
			
		||||
pytestmark = []
 | 
			
		||||
if settings.GRAPHENE_ENABLE_FILTERING:
 | 
			
		||||
if DJANGO_FILTER_INSTALLED:
 | 
			
		||||
    import django_filters
 | 
			
		||||
    from graphene.contrib.django.filter import (GlobalIDFilter, DjangoFilterConnectionField,
 | 
			
		||||
                                                GlobalIDMultipleChoiceFilter)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +1,17 @@
 | 
			
		|||
import pytest
 | 
			
		||||
from django.core.exceptions import ImproperlyConfigured
 | 
			
		||||
 | 
			
		||||
from graphene.contrib.django import settings
 | 
			
		||||
from graphene.contrib.django.tests.models import Reporter, Article
 | 
			
		||||
from graphene.contrib.django.tests.test_resolvers import ReporterNode, ArticleNode
 | 
			
		||||
from graphene.contrib.django.utils import DJANGO_FILTER_INSTALLED
 | 
			
		||||
 | 
			
		||||
if settings.GRAPHENE_ENABLE_FILTERING:
 | 
			
		||||
if DJANGO_FILTER_INSTALLED:
 | 
			
		||||
    from graphene.contrib.django.filter.resolvers import FilterConnectionResolver
 | 
			
		||||
    from graphene.contrib.django.tests.filter.filters import ReporterFilter, ArticleFilter
 | 
			
		||||
else:
 | 
			
		||||
    pytestmark = pytest.mark.skipif(True, reason='django_filters not installed')
 | 
			
		||||
 | 
			
		||||
from graphene.contrib.django.tests.models import Reporter, Article
 | 
			
		||||
from graphene.contrib.django.tests.test_resolvers import ReporterNode, ArticleNode
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_filter_get_filterset_class_explicit():
 | 
			
		||||
    reporter = Reporter(id=1, first_name='Cookie Monster')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@ import inspect
 | 
			
		|||
import six
 | 
			
		||||
from django.db import models
 | 
			
		||||
 | 
			
		||||
from graphene.contrib.django import settings
 | 
			
		||||
from ...core.classtypes.objecttype import ObjectType, ObjectTypeMeta
 | 
			
		||||
from ...relay.types import Connection, Node, NodeMeta
 | 
			
		||||
from .utils import DJANGO_FILTER_INSTALLED
 | 
			
		||||
from .converter import convert_django_field
 | 
			
		||||
from .options import DjangoOptions
 | 
			
		||||
from .utils import get_reverse_fields, maybe_queryset
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +104,7 @@ class DjangoConnection(Connection):
 | 
			
		|||
 | 
			
		||||
django_node_meta_bases = (DjangoObjectTypeMeta, NodeMeta)
 | 
			
		||||
# Only include filter functionality if available
 | 
			
		||||
if settings.GRAPHENE_ENABLE_FILTERING:
 | 
			
		||||
if DJANGO_FILTER_INSTALLED:
 | 
			
		||||
    django_node_meta_bases = (DjangoFilterObjectTypeMeta,) + django_node_meta_bases
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,12 @@ from graphene.utils import LazyList
 | 
			
		|||
 | 
			
		||||
from graphene import Argument, String
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    import django_filters  # noqa
 | 
			
		||||
    DJANGO_FILTER_INSTALLED = True
 | 
			
		||||
except ImportError:
 | 
			
		||||
    DJANGO_FILTER_INSTALLED = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_type_for_model(schema, model):
 | 
			
		||||
    schema = schema
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user