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

Clean up CustomField regex validation

Jeremy Stretch 5 лет назад
Родитель
Сommit
3d6bf1e0f8
2 измененных файлов с 14 добавлено и 3 удалено
  1. 10 1
      netbox/extras/admin.py
  2. 4 2
      netbox/extras/models/customfields.py

+ 10 - 1
netbox/extras/admin.py

@@ -75,6 +75,14 @@ class CustomFieldForm(forms.ModelForm):
     class Meta:
         model = CustomField
         exclude = []
+        widgets = {
+            'validation_regex': forms.Textarea(
+                attrs={
+                    'cols': 80,
+                    'rows': 3,
+                }
+            )
+        }
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -109,7 +117,8 @@ class CustomFieldAdmin(admin.ModelAdmin):
             'fields': ('content_types',)
         }),
         ('Validation Rules', {
-            'fields': ('validation_minimum', 'validation_maximum', 'validation_regex')
+            'fields': ('validation_minimum', 'validation_maximum', 'validation_regex'),
+            'classes': ('monospace',)
         }),
         ('Choices', {
             'description': 'A selection field must have two or more choices assigned to it.',

+ 4 - 2
netbox/extras/models/customfields.py

@@ -70,7 +70,8 @@ class CustomField(models.Model):
     )
     name = models.CharField(
         max_length=50,
-        unique=True
+        unique=True,
+        help_text='Internal field name'
     )
     label = models.CharField(
         max_length=50,
@@ -120,7 +121,8 @@ class CustomField(models.Model):
         validators=[validate_regex],
         max_length=500,
         verbose_name='Validation regex',
-        help_text='Regular expression to enforce on text field values'
+        help_text='Regular expression to enforce on text field values. Use ^ and $ to force matching of entire string. '
+                  'For example, <code>^[A-Z]{3}$</code> will limit values to exactly three uppercase letters.'
     )
     choices = ArrayField(
         base_field=models.CharField(max_length=100),