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'
)
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):
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 virtualization.models import Cluster
from wireless.models import WirelessLAN, WirelessLANGroup
from .common import InterfaceCommonForm, ModuleCommonForm
from .common import COMPONENT_BULK_CREATE_HELP_TEXT, InterfaceCommonForm, ModuleCommonForm
__all__ = (
'CableForm',
@ -909,6 +909,9 @@ class ModularComponentTemplateForm(ComponentTemplateForm):
if self.instance.pk:
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):
fieldsets = (

View File

@ -7,6 +7,7 @@ from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultiple
from utilities.forms.rendering import FieldSet
from utilities.forms.widgets import APISelect
from . import model_forms
from .common import COMPONENT_BULK_CREATE_HELP_TEXT
__all__ = (
'ComponentCreateForm',
@ -57,11 +58,7 @@ class ComponentCreateForm(forms.Form):
# Components attached to a module need to present this standardized substitution help text.
if 'module' in self.fields:
self.fields['name'].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."
)
self.fields['name'].help_text = _(COMPONENT_BULK_CREATE_HELP_TEXT)
def clean(self):
super().clean()