mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 20:32:25 -06:00
Closes #13149: Wrap form field labels with gettext_lazy()
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dcim.models import *
|
||||
from netbox.forms import NetBoxModelForm
|
||||
@@ -38,8 +38,11 @@ class ComponentCreateForm(forms.Form):
|
||||
Subclass this form when facilitating the creation of one or more component or component template objects based on
|
||||
a name pattern.
|
||||
"""
|
||||
name = ExpandableNameField()
|
||||
name = ExpandableNameField(
|
||||
label=_('Name'),
|
||||
)
|
||||
label = ExpandableNameField(
|
||||
label=_('Label'),
|
||||
required=False,
|
||||
help_text=_('Alphanumeric ranges are supported. (Must match the number of objects being created.)')
|
||||
)
|
||||
@@ -57,8 +60,9 @@ class ComponentCreateForm(forms.Form):
|
||||
value_count = len(self.cleaned_data[field_name])
|
||||
if self.cleaned_data[field_name] and value_count != pattern_count:
|
||||
raise forms.ValidationError({
|
||||
field_name: f'The provided pattern specifies {value_count} values, but {pattern_count} are '
|
||||
f'expected.'
|
||||
field_name: _(
|
||||
"The provided pattern specifies {value_count} values, but {pattern_count} are expected."
|
||||
).format(value_count=value_count, pattern_count=pattern_count)
|
||||
}, code='label_pattern_mismatch')
|
||||
|
||||
|
||||
@@ -222,12 +226,14 @@ class InterfaceCreateForm(ComponentCreateForm, model_forms.InterfaceForm):
|
||||
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'
|
||||
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(
|
||||
label=_('Device'),
|
||||
queryset=Device.objects.all(),
|
||||
selector=True,
|
||||
widget=APISelect(
|
||||
@@ -329,6 +335,7 @@ class InventoryItemCreateForm(ComponentCreateForm, model_forms.InventoryItemForm
|
||||
|
||||
class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
region = DynamicModelChoiceField(
|
||||
label=_('Region'),
|
||||
queryset=Region.objects.all(),
|
||||
required=False,
|
||||
initial_params={
|
||||
@@ -336,6 +343,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
site_group = DynamicModelChoiceField(
|
||||
label=_('Site group'),
|
||||
queryset=SiteGroup.objects.all(),
|
||||
required=False,
|
||||
initial_params={
|
||||
@@ -343,6 +351,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
site = DynamicModelChoiceField(
|
||||
label=_('Site'),
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
query_params={
|
||||
@@ -351,6 +360,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
rack = DynamicModelChoiceField(
|
||||
label=_('Rack'),
|
||||
queryset=Rack.objects.all(),
|
||||
required=False,
|
||||
null_option='None',
|
||||
@@ -359,6 +369,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
members = DynamicModelMultipleChoiceField(
|
||||
label=_('Members'),
|
||||
queryset=Device.objects.all(),
|
||||
required=False,
|
||||
query_params={
|
||||
@@ -367,6 +378,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
}
|
||||
)
|
||||
initial_position = forms.IntegerField(
|
||||
label=_('Initial position'),
|
||||
initial=1,
|
||||
required=False,
|
||||
help_text=_('Position of the first member device. Increases by one for each additional member.')
|
||||
@@ -383,7 +395,7 @@ class VirtualChassisCreateForm(NetBoxModelForm):
|
||||
|
||||
if self.cleaned_data['members'] and self.cleaned_data['initial_position'] is None:
|
||||
raise forms.ValidationError({
|
||||
'initial_position': "A position must be specified for the first VC member."
|
||||
'initial_position': _("A position must be specified for the first VC member.")
|
||||
})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user