Reuse help text string in both ComponentCreateForm and ModularComponentTemplateForm

This commit is contained in:
Brian Tiemann 2024-11-15 13:33:13 -05:00
parent d6bde32056
commit 37b5413e45
3 changed files with 12 additions and 6 deletions

View File

@ -10,6 +10,12 @@ __all__ = (
'ModuleCommonForm' 'ModuleCommonForm'
) )
COMPONENT_BULK_CREATE_HELP_TEXT = (
"Alphanumeric ranges are supported for bulk creation. Mixed cases and types "
"within a single range are not supported (example: <code>[ge,xe]-0/0/[0-9]</code>). The string "
"<code>{module}</code> will be replaced with the position of the assigned module, if any."
)
class InterfaceCommonForm(forms.Form): class InterfaceCommonForm(forms.Form):
mac_address = forms.CharField( mac_address = forms.CharField(

View File

@ -19,7 +19,7 @@ from utilities.forms.rendering import FieldSet, InlineFields, TabbedGroups
from utilities.forms.widgets import APISelect, ClearableFileInput, HTMXSelect, NumberWithOptions, SelectWithPK from utilities.forms.widgets import APISelect, ClearableFileInput, HTMXSelect, NumberWithOptions, SelectWithPK
from virtualization.models import Cluster from virtualization.models import Cluster
from wireless.models import WirelessLAN, WirelessLANGroup from wireless.models import WirelessLAN, WirelessLANGroup
from .common import InterfaceCommonForm, ModuleCommonForm from .common import COMPONENT_BULK_CREATE_HELP_TEXT, InterfaceCommonForm, ModuleCommonForm
__all__ = ( __all__ = (
'CableForm', 'CableForm',
@ -909,6 +909,9 @@ class ModularComponentTemplateForm(ComponentTemplateForm):
if self.instance.pk: if self.instance.pk:
self.fields['module_type'].disabled = True self.fields['module_type'].disabled = True
# Components attached to a module need to present this standardized substitution help text.
self.fields['name'].help_text = _(COMPONENT_BULK_CREATE_HELP_TEXT)
class ConsolePortTemplateForm(ModularComponentTemplateForm): class ConsolePortTemplateForm(ModularComponentTemplateForm):
fieldsets = ( fieldsets = (

View File

@ -7,6 +7,7 @@ from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultiple
from utilities.forms.rendering import FieldSet from utilities.forms.rendering import FieldSet
from utilities.forms.widgets import APISelect from utilities.forms.widgets import APISelect
from . import model_forms from . import model_forms
from .common import COMPONENT_BULK_CREATE_HELP_TEXT
__all__ = ( __all__ = (
'ComponentCreateForm', 'ComponentCreateForm',
@ -57,11 +58,7 @@ class ComponentCreateForm(forms.Form):
# Components attached to a module need to present this standardized substitution help text. # Components attached to a module need to present this standardized substitution help text.
if 'module' in self.fields: if 'module' in self.fields:
self.fields['name'].help_text = _( self.fields['name'].help_text = _(COMPONENT_BULK_CREATE_HELP_TEXT)
"Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range are "
"not supported (example: <code>[ge,xe]-0/0/[0-9]</code>). The string <code>{module}</code> will be "
"replaced with the position of the assigned module, if any."
)
def clean(self): def clean(self):
super().clean() super().clean()