From ba7dbcfc4f79e2be24062133120331ae26a8abb7 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 4 Nov 2024 15:49:53 -0500 Subject: [PATCH 1/6] Move {module} substitution help text to main ComponentCreateForm.__init__ so it applies to all component types, and fix formatting --- netbox/dcim/forms/object_create.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/netbox/dcim/forms/object_create.py b/netbox/dcim/forms/object_create.py index d18c7ed1448..412fcececb9 100644 --- a/netbox/dcim/forms/object_create.py +++ b/netbox/dcim/forms/object_create.py @@ -52,6 +52,19 @@ class ComponentCreateForm(forms.Form): # ComponentCreateView when creating objects. replication_fields = ('name', 'label') + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # Components attached to a module need to present this standardized substitution help text. + if 'module' in self.fields: + help_text_parts = [] + if self.fields['name'].help_text: + help_text_parts.append(self.fields['name'].help_text) + help_text_parts.append(_( + "The string {module} will be replaced with the position of the assigned module, if any." + )) + self.fields['name'].help_text = ' '.join([str(x) for x in help_text_parts]) + def clean(self): super().clean() @@ -243,14 +256,6 @@ class InterfaceCreateForm(ComponentCreateForm, model_forms.InterfaceForm): class Meta(model_forms.InterfaceForm.Meta): exclude = ('name', 'label') - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - if 'module' in self.fields: - self.fields['name'].help_text += _( - "The string {module} will be replaced with the position of the assigned module, if any." - ) - class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm): device = DynamicModelChoiceField( From d6bde32056f94e8c97b2a50caece6a507b737146 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Fri, 8 Nov 2024 10:26:13 -0500 Subject: [PATCH 2/6] Simplify help text replacement string for component forms with 'module' field --- netbox/dcim/forms/object_create.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/netbox/dcim/forms/object_create.py b/netbox/dcim/forms/object_create.py index 412fcececb9..fd8b88a8abe 100644 --- a/netbox/dcim/forms/object_create.py +++ b/netbox/dcim/forms/object_create.py @@ -57,13 +57,11 @@ def __init__(self, *args, **kwargs): # Components attached to a module need to present this standardized substitution help text. if 'module' in self.fields: - help_text_parts = [] - if self.fields['name'].help_text: - help_text_parts.append(self.fields['name'].help_text) - help_text_parts.append(_( - "The string {module} will be replaced with the position of the assigned module, if any." - )) - self.fields['name'].help_text = ' '.join([str(x) for x in help_text_parts]) + self.fields['name'].help_text = _( + "Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range are " + "not supported (example: [ge,xe]-0/0/[0-9]). The string {module} will be " + "replaced with the position of the assigned module, if any." + ) def clean(self): super().clean() From 37b5413e45f45168ce31ed57bb93a4b2cb62921a Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Fri, 15 Nov 2024 13:33:13 -0500 Subject: [PATCH 3/6] Reuse help text string in both ComponentCreateForm and ModularComponentTemplateForm --- netbox/dcim/forms/common.py | 6 ++++++ netbox/dcim/forms/model_forms.py | 5 ++++- netbox/dcim/forms/object_create.py | 7 ++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/netbox/dcim/forms/common.py b/netbox/dcim/forms/common.py index 4341ec04110..b42d5d81584 100644 --- a/netbox/dcim/forms/common.py +++ b/netbox/dcim/forms/common.py @@ -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: [ge,xe]-0/0/[0-9]). The string " + "{module} will be replaced with the position of the assigned module, if any." +) + class InterfaceCommonForm(forms.Form): mac_address = forms.CharField( diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 908312a8a4a..5ca5690dcfe 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -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', @@ -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 = ( diff --git a/netbox/dcim/forms/object_create.py b/netbox/dcim/forms/object_create.py index fd8b88a8abe..9222e5c9055 100644 --- a/netbox/dcim/forms/object_create.py +++ b/netbox/dcim/forms/object_create.py @@ -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', @@ -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: [ge,xe]-0/0/[0-9]). The string {module} 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() From d0b7135dd8102415bae05a55348ec60c2f9a8844 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Wed, 20 Nov 2024 19:26:04 -0500 Subject: [PATCH 4/6] Remove help text override from regular (direct) object creation of device components --- netbox/dcim/forms/common.py | 7 ------- netbox/dcim/forms/model_forms.py | 8 ++++++-- netbox/dcim/forms/object_create.py | 8 -------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/netbox/dcim/forms/common.py b/netbox/dcim/forms/common.py index b42d5d81584..0889583cffc 100644 --- a/netbox/dcim/forms/common.py +++ b/netbox/dcim/forms/common.py @@ -10,13 +10,6 @@ '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: [ge,xe]-0/0/[0-9]). The string " - "{module} will be replaced with the position of the assigned module, if any." -) - - class InterfaceCommonForm(forms.Form): mac_address = forms.CharField( empty_value=None, diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 5ca5690dcfe..45593013c52 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -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 COMPONENT_BULK_CREATE_HELP_TEXT, InterfaceCommonForm, ModuleCommonForm +from .common import InterfaceCommonForm, ModuleCommonForm __all__ = ( 'CableForm', @@ -910,7 +910,11 @@ def __init__(self, *args, **kwargs): 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) + self.fields['name'].help_text = _( + "Alphanumeric ranges are supported for bulk creation. Mixed cases and types " + "within a single range are not supported (example: [ge,xe]-0/0/[0-9]). The string " + "{module} will be replaced with the position of the assigned module, if any." + ) class ConsolePortTemplateForm(ModularComponentTemplateForm): diff --git a/netbox/dcim/forms/object_create.py b/netbox/dcim/forms/object_create.py index 9222e5c9055..85c613b8c68 100644 --- a/netbox/dcim/forms/object_create.py +++ b/netbox/dcim/forms/object_create.py @@ -7,7 +7,6 @@ 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', @@ -53,13 +52,6 @@ class ComponentCreateForm(forms.Form): # ComponentCreateView when creating objects. replication_fields = ('name', 'label') - def __init__(self, *args, **kwargs): - super().__init__(*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 = _(COMPONENT_BULK_CREATE_HELP_TEXT) - def clean(self): super().clean() From 663b7f89018098c30e3c8816a5d0bec43262f069 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Wed, 20 Nov 2024 19:26:49 -0500 Subject: [PATCH 5/6] Re-add space --- netbox/dcim/forms/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netbox/dcim/forms/common.py b/netbox/dcim/forms/common.py index 0889583cffc..4341ec04110 100644 --- a/netbox/dcim/forms/common.py +++ b/netbox/dcim/forms/common.py @@ -10,6 +10,7 @@ 'ModuleCommonForm' ) + class InterfaceCommonForm(forms.Form): mac_address = forms.CharField( empty_value=None, From 8ee14409c2f8039c3cb1bebfe940870dabf7e4c3 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 21 Nov 2024 11:46:51 -0500 Subject: [PATCH 6/6] Tweak help text --- netbox/dcim/forms/model_forms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 45593013c52..8f9c4227dc0 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -911,9 +911,9 @@ def __init__(self, *args, **kwargs): # Components attached to a module need to present this standardized substitution help text. self.fields['name'].help_text = _( - "Alphanumeric ranges are supported for bulk creation. Mixed cases and types " - "within a single range are not supported (example: [ge,xe]-0/0/[0-9]). The string " - "{module} will be replaced with the position of the assigned module, if any." + "Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range are not " + "supported (example: [ge,xe]-0/0/[0-9]). The token {module}, if present, will be " + "automatically replaced with the position value when creating a new module." )