mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 01:47:57 +03:00 
			
		
		
		
	Move to_const function from Graphene into Graphene-Django (#992)
This commit is contained in:
		
							parent
							
								
									3026181b28
								
							
						
					
					
						commit
						1bec8e44b7
					
				| 
						 | 
				
			
			@ -20,13 +20,14 @@ from graphene import (
 | 
			
		|||
    Time,
 | 
			
		||||
)
 | 
			
		||||
from graphene.types.json import JSONString
 | 
			
		||||
from graphene.utils.str_converters import to_camel_case, to_const
 | 
			
		||||
from graphene.utils.str_converters import to_camel_case
 | 
			
		||||
from graphql import assert_valid_name
 | 
			
		||||
 | 
			
		||||
from .settings import graphene_settings
 | 
			
		||||
from .compat import ArrayField, HStoreField, JSONField, RangeField
 | 
			
		||||
from .fields import DjangoListField, DjangoConnectionField
 | 
			
		||||
from .utils import import_single_dispatch
 | 
			
		||||
from .utils.str_converters import to_const
 | 
			
		||||
 | 
			
		||||
singledispatch = import_single_dispatch()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								graphene_django/utils/str_converters.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								graphene_django/utils/str_converters.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
import re
 | 
			
		||||
from unidecode import unidecode
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_const(string):
 | 
			
		||||
    return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()
 | 
			
		||||
							
								
								
									
										0
									
								
								graphene_django/utils/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								graphene_django/utils/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										10
									
								
								graphene_django/utils/tests/test_str_converters.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								graphene_django/utils/tests/test_str_converters.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
# coding: utf-8
 | 
			
		||||
from ..str_converters import to_const
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_to_const():
 | 
			
		||||
    assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_to_const_unicode():
 | 
			
		||||
    assert to_const(u"Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user