Skip to content

Commit 08d0cce

Browse files
Jean-Louis Fuchsjkimbo
Jean-Louis Fuchs
andauthored
Move to_const function from Graphene into Graphene-Django (#992) (#996)
Co-authored-by: Jonathan Kim <[email protected]>
1 parent f8b88fd commit 08d0cce

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

graphene_django/converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
Time,
2323
)
2424
from graphene.types.json import JSONString
25-
from graphene.utils.str_converters import to_camel_case, to_const
25+
from graphene.utils.str_converters import to_camel_case
2626
from graphql import GraphQLError, assert_valid_name
2727
from graphql.pyutils import register_description
2828

2929
from .compat import ArrayField, HStoreField, JSONField, RangeField
3030
from .fields import DjangoConnectionField, DjangoListField
3131
from .settings import graphene_settings
32+
from .utils.str_converters import to_const
3233

3334

3435
def convert_choice_name(name):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import re
2+
from unidecode import unidecode
3+
4+
5+
def to_const(string):
6+
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()

graphene_django/utils/tests/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ..str_converters import to_const
2+
3+
4+
def test_to_const():
5+
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"
6+
7+
8+
def test_to_const_unicode():
9+
assert to_const(u"Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"graphql-core>=3.1.0,<4",
5959
"Django>=2.2",
6060
"promise>=2.1",
61+
"unidecode>=1.1.1,<2",
6162
],
6263
setup_requires=["pytest-runner"],
6364
tests_require=tests_require,

0 commit comments

Comments
 (0)