Skip to content

Commit

Permalink
Reuse help text string in both ComponentCreateForm and ModularCompone…
Browse files Browse the repository at this point in the history
…ntTemplateForm
  • Loading branch information
bctiemann committed Nov 15, 2024
1 parent d6bde32 commit 37b5413
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions netbox/dcim/forms/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
'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(
Expand Down
5 changes: 4 additions & 1 deletion netbox/dcim/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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',
Expand Down Expand Up @@ -909,6 +909,9 @@ def __init__(self, *args, **kwargs):
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 = (
Expand Down
7 changes: 2 additions & 5 deletions netbox/dcim/forms/object_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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',
Expand Down Expand Up @@ -57,11 +58,7 @@ def __init__(self, *args, **kwargs):

# 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()
Expand Down

0 comments on commit 37b5413

Please sign in to comment.