Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move color pattern to a constant

Artur Smęt2fff2bc4f69b
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 1008df5fbe..4a08bbdc36 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -18,6 +18,8 @@ from ..core.types.money import (
from ..utils import get_database_id
from .filters import ProductFilterSet
+COLOR_PATTERN = r'^(#[0-9a-fA-F]{3}|#(?:[0-9a-fA-F]{2}){2,4}|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))$' # noqa
+
class ProductAttribuetValueType(graphene.Enum):
COLOR = 'COLOR'
@@ -45,8 +47,7 @@ def resolve_attribute_list(attributes):
def resolve_attribute_value_type(attribute_value):
- color_pattern = '^(#[0-9a-fA-F]{3}|#(?:[0-9a-fA-F]{2}){2,4}|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))$' # noqa
- color_pattern = re.compile(color_pattern)
+ color_pattern = re.compile(COLOR_PATTERN)
if color_pattern.match(attribute_value):
return ProductAttribuetValueType.COLOR
if 'gradient(' in attribute_value: