From ba7dbcfc4f79e2be24062133120331ae26a8abb7 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 4 Nov 2024 15:49:53 -0500 Subject: [PATCH] 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 d18c7ed14..412fcecec 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(