Skip to content

Commit

Permalink
feat: set fixed descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SquakR committed Feb 17, 2022
1 parent 3cd55ac commit f4effe7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 146 deletions.
10 changes: 0 additions & 10 deletions graphene_django_filter/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings as django_settings
from django.db import connection
from django.test.signals import setting_changed
from django.utils.translation import gettext_lazy as _


def get_fixed_settings() -> Dict[str, bool]:
Expand All @@ -28,15 +27,6 @@ def get_fixed_settings() -> Dict[str, bool]:
'AND_KEY': 'and',
'OR_KEY': 'or',
'NOT_KEY': 'not',
'MESSAGES': {
'FILTER_DESCRIPTION': _('FILTER_DESCRIPTION'),
'AND_DESCRIPTION': _('AND_DESCRIPTION'),
'OR_DESCRIPTION': _('OR_DESCRIPTION'),
'NOT_DESCRIPTION': _('NOT_DESCRIPTION'),
'FIELD_DESCRIPTION': _('FIELD_DESCRIPTION'),
'SUBFIELD_DESCRIPTION': _('SUBFIELD_DESCRIPTION'),
'LOOKUP_DESCRIPTION': _('LOOKUP_DESCRIPTION'),
},
}
DJANGO_SETTINGS_KEY = 'GRAPHENE_DJANGO_FILTER'

Expand Down
25 changes: 8 additions & 17 deletions graphene_django_filter/input_type_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from anytree import Node
from django.db import models
from django.db.models.constants import LOOKUP_SEP
from django.utils.text import format_lazy
from django_filters import Filter
from django_filters.conf import settings as django_settings
from graphene_django.filter.utils import get_model_field
Expand All @@ -31,7 +30,7 @@ def get_filtering_args_from_filterset(
filterset_to_trees(filterset_class),
filterset_class,
node_type.__name__.replace('Type', ''),
), description=settings.MESSAGES['FILTER_DESCRIPTION'],
), description='Advanced filter field',
),
}

Expand All @@ -51,24 +50,21 @@ def create_filter_input_type(
**{
root.name: graphene.InputField(
create_filter_input_subtype(root, filterset_class, type_name),
description=format_lazy(
settings.MESSAGES['FIELD_DESCRIPTION'],
field=pascalcase(root.name),
),
description=f'`{pascalcase(root.name)}` field',
)
for root in roots
},
settings.AND_KEY: graphene.InputField(
graphene.List(lambda: input_type),
description=settings.MESSAGES['AND_DESCRIPTION'],
description='`And` field',
),
settings.OR_KEY: graphene.InputField(
graphene.List(lambda: input_type),
description=settings.MESSAGES['OR_DESCRIPTION'],
description='`Or` field',
),
settings.NOT_KEY: graphene.InputField(
lambda: input_type,
description=settings.MESSAGES['NOT_DESCRIPTION'],
description='`Not` field',
),
},
),
Expand Down Expand Up @@ -100,10 +96,7 @@ def create_filter_input_subtype(
filterset_class,
prefix + pascalcase(root.name),
),
description=format_lazy(
settings.MESSAGES['SUBFIELD_DESCRIPTION'],
subfield=pascalcase(child.name),
),
description=f'`{pascalcase(child.name)}` subfield',
)
return create_input_object_type(
f'{prefix}{pascalcase(root.name)}FilterInputType',
Expand Down Expand Up @@ -151,10 +144,8 @@ def get_field(
if filter_type in ('in', 'range'):
field = graphene.List(field.get_type())
field_type = field.InputField()
field_type.description = getattr(filter_field, 'label') or format_lazy(
settings.MESSAGES['LOOKUP_DESCRIPTION'],
lookup=pascalcase(filter_field.lookup_expr),
)
field_type.description = getattr(filter_field, 'label') or \
f'`{pascalcase(filter_field.lookup_expr)}` lookup'
return field_type


Expand Down
60 changes: 38 additions & 22 deletions graphene_django_filter/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
class SearchConfigInputType(graphene.InputObjectType):
"""Input type for the `SearchVector` or `SearchQuery` object config."""

value = graphene.String()
is_field = graphene.Boolean(default=False)
value = graphene.String(description='`SearchVector` or `SearchQuery` object config value')
is_field = graphene.Boolean(
default=False,
description='Whether to wrap the value with the F object',
)


class SearchVectorWeight(graphene.Enum):
Expand All @@ -26,9 +29,13 @@ class SearchVectorWeight(graphene.Enum):
class SearchVectorInputType(graphene.InputObjectType):
"""Input type for creating the `SearchVector` object."""

fields = graphene.List(graphene.NonNull(graphene.String), required=True)
config = graphene.InputField(SearchConfigInputType)
weight = graphene.InputField(SearchVectorWeight)
fields = graphene.InputField(
graphene.List(graphene.NonNull(graphene.String)),
required=True,
description='Field names of vector',
)
config = graphene.InputField(SearchConfigInputType, description='Vector config'),
weight = graphene.InputField(SearchVectorWeight, 'Vector weight')


class SearchQueryType(graphene.Enum):
Expand All @@ -49,11 +56,20 @@ def create_search_query_input_type() -> Type[graphene.InputObjectType]:
(graphene.InputObjectType,),
{
'__doc__': 'Input type for creating the `SearchQuery` object.',
'value': graphene.String(required=True),
'config': graphene.InputField(SearchConfigInputType),
settings.AND_KEY: graphene.List(lambda: search_query_input_type),
settings.OR_KEY: graphene.List(lambda: search_query_input_type),
settings.NOT_KEY: graphene.List(lambda: search_query_input_type),
'value': graphene.String(required=True, description='Query value'),
'config': graphene.InputField(SearchConfigInputType, description='Query config'),
settings.AND_KEY: graphene.InputField(
graphene.List(lambda: search_query_input_type),
description='`And` field',
),
settings.OR_KEY: graphene.InputField(
graphene.List(lambda: search_query_input_type),
description='`Or` field',
),
settings.NOT_KEY: graphene.InputField(
graphene.List(lambda: search_query_input_type),
description='`Not` field',
),
},
),
)
Expand All @@ -66,26 +82,26 @@ def create_search_query_input_type() -> Type[graphene.InputObjectType]:
class SearchQueryFilterInputType(graphene.InputObjectType):
"""Input type for the full text search using the `SearchQueryFilter` class."""

vector = graphene.InputField(SearchVectorInputType)
query = graphene.InputField(SearchQueryInputType)
vector = graphene.InputField(SearchVectorInputType, description='Search vector')
query = graphene.InputField(SearchQueryInputType, description='Search query')


class FloatLookups(graphene.InputObjectType):
"""Input type for float lookups."""

exact = graphene.Float()
gt = graphene.Float()
gte = graphene.Float()
lt = graphene.Float()
lte = graphene.Float()
exact = graphene.Float('Is exact')
gt = graphene.Float('Is greater than')
gte = graphene.Float('Is greater than or equal to')
lt = graphene.Float('Is less than')
lte = graphene.Float('Is less than or equal to')


class SearchRankFilterInputType(graphene.InputObjectType):
"""Input type for the full text search using the `SearchRankFilter` class."""

vector = graphene.InputField(SearchVectorInputType)
query = graphene.InputField(SearchQueryInputType)
value = graphene.InputField(FloatLookups)
vector = graphene.InputField(SearchVectorInputType, description='Search vector')
query = graphene.InputField(SearchQueryInputType, description='Search query')
value = graphene.InputField(FloatLookups, description='Available lookups')


class TrigramSearchType(graphene.Enum):
Expand All @@ -98,5 +114,5 @@ class TrigramSearchType(graphene.Enum):
class TrigramFilterInputType(graphene.InputObjectType):
"""Input type for the full text search using the `TrigramFilter` class."""

kind = graphene.InputField(TrigramSearchType)
value = graphene.InputField(FloatLookups)
kind = graphene.InputField(TrigramSearchType, description='Type of the search using trigrams')
value = graphene.InputField(FloatLookups, description='Available lookups')
Binary file removed graphene_django_filter/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
47 changes: 0 additions & 47 deletions graphene_django_filter/locale/en/LC_MESSAGES/django.po

This file was deleted.

Binary file not shown.
49 changes: 0 additions & 49 deletions graphene_django_filter/locale/ru/LC_MESSAGES/django.po

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_initial(self) -> None:
self.assertEqual('and', conf.settings.AND_KEY)
self.assertEqual('or', conf.settings.OR_KEY)
self.assertEqual('not', conf.settings.NOT_KEY)
self.assertIsInstance(conf.settings.MESSAGES, dict)

def test_overridden(self) -> None:
"""Test overridden settings."""
Expand Down

0 comments on commit f4effe7

Please sign in to comment.