Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #17459 - Ensure help text on component create forms shows both bulk edit and substitution token instructions #17931

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions netbox/dcim/forms/object_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
bctiemann marked this conversation as resolved.
Show resolved Hide resolved
help_text_parts = []
if self.fields['name'].help_text:
help_text_parts.append(self.fields['name'].help_text)
help_text_parts.append(_(
"The string <code>{module}</code> 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])
bctiemann marked this conversation as resolved.
Show resolved Hide resolved

def clean(self):
super().clean()

Expand Down Expand Up @@ -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 <code>{module}</code> will be replaced with the position of the assigned module, if any."
)


class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm):
device = DynamicModelChoiceField(
Expand Down