Просмотр исходного кода

Move SLUG_RE to utilities.constants for reuse by event rule actions and exporters

Jeremy Stretch 6 дней назад
Родитель
Сommit
a25626a63a
3 измененных файлов с 14 добавлено и 11 удалено
  1. 1 7
      netbox/netbox/event_rules.py
  2. 1 4
      netbox/netbox/exporters.py
  3. 12 0
      netbox/utilities/constants.py

+ 1 - 7
netbox/netbox/event_rules.py

@@ -1,11 +1,10 @@
-import re
-
 from django.core.exceptions import ImproperlyConfigured, ValidationError
 from django.utils.text import capfirst
 from django.utils.translation import gettext_lazy as _
 
 from netbox.registry import registry
 from utilities.choices import Choice
+from utilities.constants import SLUG_RE
 from utilities.string import enum_key
 
 __all__ = (
@@ -16,11 +15,6 @@ __all__ = (
     'register_event_rule_action',
 )
 
-# A slug must sanitize (via enum_key()) into a valid GraphQL enum member name, which rules out a
-# leading digit or underscore. Hyphens are rejected outright rather than sanitized away, so that a
-# slug always reads as it was written.
-SLUG_RE = re.compile(r'^[a-z][a-z0-9_]*(\.[a-z0-9_]+)*$')
-
 
 # This module must not import any concrete Django models: it's imported by netbox.plugins (itself
 # imported by netbox.settings, before the app registry is populated), so only registry-level

+ 1 - 4
netbox/netbox/exporters.py

@@ -1,5 +1,4 @@
 import csv
-import re
 from itertools import chain
 
 from django.conf import settings
@@ -8,7 +7,7 @@ from django.db.models import FETCH_PEERS
 from django.utils.translation import gettext as _
 
 from netbox.registry import registry
-from utilities.constants import CSV_DELIMITERS
+from utilities.constants import CSV_DELIMITERS, SLUG_RE
 
 __all__ = (
     'CSVExporter',
@@ -20,8 +19,6 @@ __all__ = (
     'register_exporter',
 )
 
-SLUG_RE = re.compile(r'^[a-z][a-z0-9_]*(\.[a-z0-9_]+)*$')
-
 
 class Exporter:
     """

+ 12 - 0
netbox/utilities/constants.py

@@ -1,3 +1,5 @@
+import re
+
 #
 # Filter lookup expressions
 #
@@ -126,3 +128,13 @@ IMAGE_URL_SCHEMES = {'http', 'https'}
 HTTP_PROXY_SUPPORTED_SOCK_SCHEMAS = ['socks4', 'socks4a', 'socks4h', 'socks5', 'socks5a', 'socks5h']
 HTTP_PROXY_SOCK_RDNS_SCHEMAS = ['socks4h', 'socks4a', 'socks5h', 'socks5a']
 HTTP_PROXY_SUPPORTED_SCHEMAS = ['http', 'https', 'socks4', 'socks4a', 'socks4h', 'socks5', 'socks5a', 'socks5h']
+
+
+#
+# Registered component slugs (e.g. event rule actions & exporters)
+#
+
+# An event rule action slug must sanitize (via enum_key()) into a valid GraphQL enum member name, which rules out a
+# leading digit or underscore. Hyphens are rejected outright rather than sanitized away, so that a slug always reads as
+# it was written.
+SLUG_RE = re.compile(r'^[a-z][a-z0-9_]*(\.[a-z0-9_]+)*$')