From f4effe75a749f351b238c06ee9f6e5cd18944d3e Mon Sep 17 00:00:00 2001 From: squak Date: Thu, 17 Feb 2022 06:27:11 +0300 Subject: [PATCH] feat: set fixed descriptions --- graphene_django_filter/conf.py | 10 --- .../input_type_factories.py | 25 +++----- graphene_django_filter/input_types.py | 60 +++++++++++------- .../locale/en/LC_MESSAGES/django.mo | Bin 761 -> 0 bytes .../locale/en/LC_MESSAGES/django.po | 47 -------------- .../locale/ru/LC_MESSAGES/django.mo | Bin 1032 -> 0 bytes .../locale/ru/LC_MESSAGES/django.po | 49 -------------- tests/test_conf.py | 1 - 8 files changed, 46 insertions(+), 146 deletions(-) delete mode 100644 graphene_django_filter/locale/en/LC_MESSAGES/django.mo delete mode 100644 graphene_django_filter/locale/en/LC_MESSAGES/django.po delete mode 100644 graphene_django_filter/locale/ru/LC_MESSAGES/django.mo delete mode 100644 graphene_django_filter/locale/ru/LC_MESSAGES/django.po diff --git a/graphene_django_filter/conf.py b/graphene_django_filter/conf.py index de91700..d4fc976 100644 --- a/graphene_django_filter/conf.py +++ b/graphene_django_filter/conf.py @@ -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]: @@ -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' diff --git a/graphene_django_filter/input_type_factories.py b/graphene_django_filter/input_type_factories.py index 7f91480..3e331f4 100644 --- a/graphene_django_filter/input_type_factories.py +++ b/graphene_django_filter/input_type_factories.py @@ -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 @@ -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', ), } @@ -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', ), }, ), @@ -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', @@ -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 diff --git a/graphene_django_filter/input_types.py b/graphene_django_filter/input_types.py index 8c6a4c7..5c069ba 100644 --- a/graphene_django_filter/input_types.py +++ b/graphene_django_filter/input_types.py @@ -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): @@ -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): @@ -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', + ), }, ), ) @@ -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): @@ -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') diff --git a/graphene_django_filter/locale/en/LC_MESSAGES/django.mo b/graphene_django_filter/locale/en/LC_MESSAGES/django.mo deleted file mode 100644 index c5f09de49bc4edaf76b7af6a3c305bcdc7a6a11c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 761 zcmZXO&2H2%5XS=)ih=}cMQJU>^LJ{SfQE%c+?gRj-`dnz{ep! zDZ3eLXPR5+2_+$ReQXo-*tcBg{!`zhCd(R)W0i@f%CuA#nk0-NkGK@=P?tDtm)Lel zqv#P>MbTyj$1%^2EyReomvooxFt%Hj8&VYu4_x3nE?u0xwXtcArO;f!cW-LANAuVE zL0x5~7@+BkOf_5&lX!x+7rySSBd#zNQ<;~du+a8lsm-8jRaW7NRL6~lM158^!-oSj zONVy_S|6gVdjr!*iO5rQRPrh}($h12JFiK8l8GtLp, YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-02-14 17:45+0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: .\graphene_django_filter\conf.py:19 -msgid "FILTER_DESCRIPTION" -msgstr "Advanced filter field" - -#: .\graphene_django_filter\conf.py:20 -msgid "AND_DESCRIPTION" -msgstr "`And` field" - -#: .\graphene_django_filter\conf.py:21 -msgid "OR_DESCRIPTION" -msgstr "`Or` field" - -#: .\graphene_django_filter\conf.py:22 -msgid "NOT_DESCRIPTION" -msgstr "`Not` field" - -#: .\graphene_django_filter\conf.py:23 -msgid "FIELD_DESCRIPTION" -msgstr "`{field}` field" - -#: .\graphene_django_filter\conf.py:24 -msgid "SUBFIELD_DESCRIPTION" -msgstr "`{subfield}` subfield" - -#: .\graphene_django_filter\conf.py:25 -msgid "LOOKUP_DESCRIPTION" -msgstr "`{lookup}` lookup" diff --git a/graphene_django_filter/locale/ru/LC_MESSAGES/django.mo b/graphene_django_filter/locale/ru/LC_MESSAGES/django.mo deleted file mode 100644 index 7ae75af6af8a2cc7ed39b510b4d448f71c77d641..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1032 zcma)$Uu)A)7{;T{KU7dQL`1weyKq?aY{{H3v!+|NrZX&QN}CQ8!DVY!qghgtRFqB7 zDeT5ey%W6g0}ORA9P4fsyg0ej8^3_xL44A!ww*T~c=(-j-sgSa=jTA*8xH3bbP2i( zorc~*$@v1Eg}y@l&<|(;`gOqHU{dct!f|K7LGT>NgWn(pI*<3jF^;N@2a|mp z;05qKcoEzMN5JnOS~;MV?F4ufItd+z`k2#wOQqvbns%X%X{m4mrXwHgkk=$0~64ecwlgTYZ)YYqZjDnKVtT3WxV0ocy zMSdWXd_~hpLDm(LQFK|=rsQ0%q?F59SiM@qs@c@Etrd}Ia$&ZTB*|#nlen1{Wuz_yO!fkkfr-p5ZaMcG4pi1<4a;K+W}R)CBN!; zHIa-jI#H_VHUi6~c|TYQMdH<4&rlkhAp2M8ig#JyB}pJdLnOKKgOVVSNx~D@@y<%4 z?NUY>ORlXBJ|m2hwYB}0tT2{Fi*V2)Nqkaj`LfcDPW#RD-+#=-n)c3&gb9;m6a%iO zCsG`H$C_-1ZIO7LZL>YLNfy}l0>@snX1u|+;%97^ZJ~_PVc+VqW4qO-Ft=y0J@}jK z6Z?Q!yYUOmY_gB6N#d9I*oj}o>o9EYH*Ckx+2@0`WMS3y{fCWu_q47=$k4T>tAMHh L9XD(&wiEvW;eJpu diff --git a/graphene_django_filter/locale/ru/LC_MESSAGES/django.po b/graphene_django_filter/locale/ru/LC_MESSAGES/django.po deleted file mode 100644 index 20589a1..0000000 --- a/graphene_django_filter/locale/ru/LC_MESSAGES/django.po +++ /dev/null @@ -1,49 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-02-14 17:46+0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" -"%100>=11 && n%100<=14)? 2 : 3);\n" - -#: .\graphene_django_filter\conf.py:19 -msgid "FILTER_DESCRIPTION" -msgstr "Поле продвинутого фильтра" - -#: .\graphene_django_filter\conf.py:20 -msgid "AND_DESCRIPTION" -msgstr "Поле типа `и`" - -#: .\graphene_django_filter\conf.py:21 -msgid "OR_DESCRIPTION" -msgstr "Поле типа `или`" - -#: .\graphene_django_filter\conf.py:22 -msgid "NOT_DESCRIPTION" -msgstr "Поле типа `не`" - -#: .\graphene_django_filter\conf.py:23 -msgid "FIELD_DESCRIPTION" -msgstr "Дочернее поле типа `{field}`" - -#: .\graphene_django_filter\conf.py:24 -msgid "SUBFIELD_DESCRIPTION" -msgstr "Дочернее поле типа `{subfield}`" - -#: .\graphene_django_filter\conf.py:25 -msgid "LOOKUP_DESCRIPTION" -msgstr "Поиск тип `{lookup}`" diff --git a/tests/test_conf.py b/tests/test_conf.py index 0dbb9e8..e260063 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -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."""