Sfoglia il codice sorgente

Fixes #22889: Render Config Revision banner fields in monospace (#22907)

Replace the obsolete Django admin `vLargeTextField` class with Tabler's
`font-monospace` utility for the four banner configuration parameters.

Define the widget styling in the parameter definitions, where the metaclass
constructs the form fields, and remove the ineffective `Meta.widgets`
overrides. Add regression coverage for all six code-oriented configuration
fields, including the two JSON fields that already use a monospace font.

Update the add-config-param skill to recommend `font-monospace` so future
textarea-backed parameters do not reintroduce the obsolete admin class.
Jason Novinger 3 giorni fa
parent
commit
d38ace89ce

+ 1 - 1
.claude/skills/add-config-param/SKILL.md

@@ -43,7 +43,7 @@ ConfigParam(
     field=forms.BooleanField,   # or IntegerField, CharField, JSONField, SimpleArrayField
     field=forms.BooleanField,   # or IntegerField, CharField, JSONField, SimpleArrayField
     # field_kwargs only when extra widget/validation config is needed:
     # field_kwargs only when extra widget/validation config is needed:
     field_kwargs={
     field_kwargs={
-        'widget': forms.Textarea(attrs={'class': 'vLargeTextField'}),
+        'widget': forms.Textarea(attrs={'class': 'font-monospace'}),
     },
     },
 ),
 ),
 ```
 ```

+ 0 - 6
netbox/core/forms/model_forms.py

@@ -168,12 +168,6 @@ class ConfigRevisionForm(forms.ModelForm, metaclass=ConfigFormMetaclass):
         model = ConfigRevision
         model = ConfigRevision
         fields = '__all__'
         fields = '__all__'
         widgets = {
         widgets = {
-            'BANNER_LOGIN': forms.Textarea(attrs={'class': 'font-monospace'}),
-            'BANNER_MAINTENANCE': forms.Textarea(attrs={'class': 'font-monospace'}),
-            'BANNER_TOP': forms.Textarea(attrs={'class': 'font-monospace'}),
-            'BANNER_BOTTOM': forms.Textarea(attrs={'class': 'font-monospace'}),
-            'CUSTOM_VALIDATORS': forms.Textarea(attrs={'class': 'font-monospace'}),
-            'PROTECTION_RULES': forms.Textarea(attrs={'class': 'font-monospace'}),
             'comment': forms.Textarea(),
             'comment': forms.Textarea(),
         }
         }
 
 

+ 25 - 0
netbox/core/tests/test_forms.py

@@ -0,0 +1,25 @@
+from django.test import TestCase
+
+from core.forms import ConfigRevisionForm
+
+
+class ConfigRevisionFormTestCase(TestCase):
+
+    def test_code_fields_render_monospace(self):
+        """
+        Config parameters that hold markup or code (banners, JSON) must render their
+        textareas in a monospace font. See #8974 and #22889.
+        """
+        form = ConfigRevisionForm()
+        monospace_fields = (
+            'BANNER_LOGIN',
+            'BANNER_MAINTENANCE',
+            'BANNER_TOP',
+            'BANNER_BOTTOM',
+            'CUSTOM_VALIDATORS',
+            'PROTECTION_RULES',
+        )
+        for name in monospace_fields:
+            with self.subTest(field=name):
+                css_classes = form[name].field.widget.attrs.get('class', '').split()
+                self.assertIn('font-monospace', css_classes)

+ 4 - 4
netbox/netbox/config/parameters.py

@@ -24,7 +24,7 @@ PARAMS = (
         description=_("Additional content to display on the login page"),
         description=_("Additional content to display on the login page"),
         field_kwargs={
         field_kwargs={
             'widget': forms.Textarea(
             'widget': forms.Textarea(
-                attrs={'class': 'vLargeTextField'}
+                attrs={'class': 'font-monospace'}
             ),
             ),
         },
         },
     ),
     ),
@@ -35,7 +35,7 @@ PARAMS = (
         description=_('Additional content to display when in maintenance mode'),
         description=_('Additional content to display when in maintenance mode'),
         field_kwargs={
         field_kwargs={
             'widget': forms.Textarea(
             'widget': forms.Textarea(
-                attrs={'class': 'vLargeTextField'}
+                attrs={'class': 'font-monospace'}
             ),
             ),
         },
         },
     ),
     ),
@@ -46,7 +46,7 @@ PARAMS = (
         description=_("Additional content to display at the top of every page"),
         description=_("Additional content to display at the top of every page"),
         field_kwargs={
         field_kwargs={
             'widget': forms.Textarea(
             'widget': forms.Textarea(
-                attrs={'class': 'vLargeTextField'}
+                attrs={'class': 'font-monospace'}
             ),
             ),
         },
         },
     ),
     ),
@@ -57,7 +57,7 @@ PARAMS = (
         description=_("Additional content to display at the bottom of every page"),
         description=_("Additional content to display at the bottom of every page"),
         field_kwargs={
         field_kwargs={
             'widget': forms.Textarea(
             'widget': forms.Textarea(
-                attrs={'class': 'vLargeTextField'}
+                attrs={'class': 'font-monospace'}
             ),
             ),
         },
         },
     ),
     ),