mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 17:47:12 +03:00
Use filter label as argument description. Fixed #16
This commit is contained in:
parent
775221c427
commit
60bcc0beef
|
@ -2,7 +2,7 @@ from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from graphene import Field, ObjectType, Schema
|
from graphene import Field, ObjectType, Schema, Argument, Float
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.forms import (GlobalIDFormField,
|
from graphene_django.forms import (GlobalIDFormField,
|
||||||
|
@ -46,10 +46,7 @@ class PetNode(DjangoObjectType):
|
||||||
|
|
||||||
|
|
||||||
def get_args(field):
|
def get_args(field):
|
||||||
if isinstance(field.args, list):
|
return field.args
|
||||||
return {arg.name: arg for arg in field.args}
|
|
||||||
else:
|
|
||||||
return field.args
|
|
||||||
|
|
||||||
|
|
||||||
def assert_arguments(field, *arguments):
|
def assert_arguments(field, *arguments):
|
||||||
|
@ -252,6 +249,22 @@ def test_global_id_field_explicit():
|
||||||
assert id_filter.field_class == GlobalIDFormField
|
assert id_filter.field_class == GlobalIDFormField
|
||||||
|
|
||||||
|
|
||||||
|
def test_filterset_descriptions():
|
||||||
|
class ArticleIdFilter(django_filters.FilterSet):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Article
|
||||||
|
fields = ['id']
|
||||||
|
|
||||||
|
max_time = django_filters.NumberFilter(method='filter_max_time', label="The maximum time")
|
||||||
|
|
||||||
|
field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
|
||||||
|
max_time = field.args['max_time']
|
||||||
|
assert isinstance(max_time, Argument)
|
||||||
|
assert max_time.type == Float
|
||||||
|
assert max_time.description == 'The maximum time'
|
||||||
|
|
||||||
|
|
||||||
def test_global_id_field_relation():
|
def test_global_id_field_relation():
|
||||||
field = DjangoFilterConnectionField(ArticleNode, fields=['reporter'])
|
field = DjangoFilterConnectionField(ArticleNode, fields=['reporter'])
|
||||||
filterset_class = field.filterset_class
|
filterset_class = field.filterset_class
|
||||||
|
|
|
@ -14,12 +14,14 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
for name, filter_field in six.iteritems(filterset_class.base_filters):
|
for name, filter_field in six.iteritems(filterset_class.base_filters):
|
||||||
field_type = convert_form_field(filter_field.field)
|
field_type = convert_form_field(filter_field.field).Argument()
|
||||||
|
field_type.description = filter_field.label
|
||||||
args[name] = field_type
|
args[name] = field_type
|
||||||
|
|
||||||
# Also add the 'order_by' field
|
# Also add the 'order_by' field
|
||||||
if filterset_class._meta.order_by:
|
if filterset_class._meta.order_by:
|
||||||
args[filterset_class.order_by_field] = String()
|
args[filterset_class.order_by_field] = String()
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user