Misc cleanup

This commit is contained in:
Jeremy Stretch 2023-07-31 12:30:16 -04:00
parent 2d5d89216d
commit e934233a27
17 changed files with 64 additions and 53 deletions

View File

@ -1299,7 +1299,7 @@ class InterfaceBulkEditForm(
vdcs = DynamicModelMultipleChoiceField( vdcs = DynamicModelMultipleChoiceField(
queryset=VirtualDeviceContext.objects.all(), queryset=VirtualDeviceContext.objects.all(),
required=False, required=False,
label=_('Virtual Device Contexts'), label=_('Virtual device contexts'),
query_params={ query_params={
'device_id': '$device', 'device_id': '$device',
} }

View File

@ -821,7 +821,7 @@ class InterfaceImportForm(NetBoxModelImportForm):
help_text=_('IEEE 802.1Q operational mode (for L2 interfaces)') help_text=_('IEEE 802.1Q operational mode (for L2 interfaces)')
) )
vrf = CSVModelChoiceField( vrf = CSVModelChoiceField(
label=_('Vrf'), label=_('VRF'),
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
required=False, required=False,
to_field_name='rd', to_field_name='rd',

View File

@ -61,8 +61,10 @@ class InterfaceCommonForm(forms.Form):
if invalid_vlans: if invalid_vlans:
raise forms.ValidationError({ raise forms.ValidationError({
'tagged_vlans': _("The tagged VLANs ({vlans}) must belong to the same site as " 'tagged_vlans': _(
"the interface's parent device/VM, or they must be global").format(vlans=', '.join(invalid_vlans)) "The tagged VLANs ({vlans}) must belong to the same site as the interface's parent device/VM, "
"or they must be global"
).format(vlans=', '.join(invalid_vlans))
}) })
@ -105,7 +107,7 @@ class ModuleCommonForm(forms.Form):
# Installing modules with placeholders require that the bay has a position value # Installing modules with placeholders require that the bay has a position value
if MODULE_TOKEN in template.name and not module_bay.position: if MODULE_TOKEN in template.name and not module_bay.position:
raise forms.ValidationError( raise forms.ValidationError(
_("Cannot install module with placeholder values in a module bay with no position defined") _("Cannot install module with placeholder values in a module bay with no position defined.")
) )
resolved_name = template.name.replace(MODULE_TOKEN, module_bay.position) resolved_name = template.name.replace(MODULE_TOKEN, module_bay.position)
@ -114,12 +116,17 @@ class ModuleCommonForm(forms.Form):
# It is not possible to adopt components already belonging to a module # It is not possible to adopt components already belonging to a module
if adopt_components and existing_item and existing_item.module: if adopt_components and existing_item and existing_item.module:
raise forms.ValidationError( raise forms.ValidationError(
_("Cannot adopt {name} '{resolved_name}' as it already belongs " _("Cannot adopt {name} '{resolved_name}' as it already belongs to a module").format(
"to a module").format(name=template.component_model.__name__, resolved_name=resolved_name) name=template.component_model.__name__,
resolved_name=resolved_name
)
) )
# If we are not adopting components we error if the component exists # If we are not adopting components we error if the component exists
if not adopt_components and resolved_name in installed_components: if not adopt_components and resolved_name in installed_components:
raise forms.ValidationError( raise forms.ValidationError(
_("{name} - {resolved_name} already exists").format(name=template.component_model.__name__, resolved_name=resolved_name) _("{name} - {resolved_name} already exists").format(
name=template.component_model.__name__,
resolved_name=resolved_name
)
) )

View File

@ -17,6 +17,8 @@ class BaseVCMemberFormSet(forms.BaseModelFormSet):
vc_position = form.cleaned_data.get('vc_position') vc_position = form.cleaned_data.get('vc_position')
if vc_position: if vc_position:
if vc_position in vc_position_list: if vc_position in vc_position_list:
error_msg = _("A virtual chassis member already exists in position {vc_position}.").format(vc_position=vc_position) error_msg = _("A virtual chassis member already exists in position {vc_position}.").format(
vc_position=vc_position
)
form.add_error('vc_position', error_msg) form.add_error('vc_position', error_msg)
vc_position_list.append(vc_position) vc_position_list.append(vc_position)

View File

@ -967,14 +967,12 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
required=False required=False
) )
component_type = ContentTypeChoiceField( component_type = ContentTypeChoiceField(
label=_('Component type'),
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
limit_choices_to=MODULAR_COMPONENT_TEMPLATE_MODELS, limit_choices_to=MODULAR_COMPONENT_TEMPLATE_MODELS,
required=False, required=False,
widget=forms.HiddenInput widget=forms.HiddenInput
) )
component_id = forms.IntegerField( component_id = forms.IntegerField(
label=_('Component id'),
required=False, required=False,
widget=forms.HiddenInput widget=forms.HiddenInput
) )
@ -1099,7 +1097,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
vdcs = DynamicModelMultipleChoiceField( vdcs = DynamicModelMultipleChoiceField(
queryset=VirtualDeviceContext.objects.all(), queryset=VirtualDeviceContext.objects.all(),
required=False, required=False,
label=_('Virtual Device Contexts'), label=_('Virtual device contexts'),
query_params={ query_params={
'device_id': '$device', 'device_id': '$device',
} }

View File

@ -60,8 +60,9 @@ class ComponentCreateForm(forms.Form):
value_count = len(self.cleaned_data[field_name]) value_count = len(self.cleaned_data[field_name])
if self.cleaned_data[field_name] and value_count != pattern_count: if self.cleaned_data[field_name] and value_count != pattern_count:
raise forms.ValidationError({ raise forms.ValidationError({
field_name: _('The provided pattern specifies {value_count} values, but {pattern_count} are ' field_name: _(
'expected.').format(value_count=value_count, pattern_count=pattern_count) "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') }, code='label_pattern_mismatch')
@ -225,8 +226,9 @@ class InterfaceCreateForm(ComponentCreateForm, model_forms.InterfaceForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if 'module' in self.fields: if 'module' in self.fields:
self.fields['name'].help_text += _(' The string <code>{module}</code> will be replaced with the position ' self.fields['name'].help_text += _(
'of the assigned module, if any') "The string <code>{module}</code> will be replaced with the position of the assigned module, if any."
)
class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm): class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm):

View File

@ -119,7 +119,7 @@ class ExportTemplateBulkEditForm(BulkEditForm):
required=False required=False
) )
mime_type = forms.CharField( mime_type = forms.CharField(
label=_('Mime type'), label=_('MIME type'),
max_length=50, max_length=50,
required=False required=False
) )
@ -176,27 +176,27 @@ class WebhookBulkEditForm(BulkEditForm):
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )
type_create = forms.NullBooleanField( type_create = forms.NullBooleanField(
label=_('Type create'), label=_('On create'),
required=False, required=False,
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )
type_update = forms.NullBooleanField( type_update = forms.NullBooleanField(
label=_('Type update'), label=_('On update'),
required=False, required=False,
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )
type_delete = forms.NullBooleanField( type_delete = forms.NullBooleanField(
label=_('Type delete'), label=_('On delete'),
required=False, required=False,
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )
type_job_start = forms.NullBooleanField( type_job_start = forms.NullBooleanField(
label=_('Type job start'), label=_('On job start'),
required=False, required=False,
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )
type_job_end = forms.NullBooleanField( type_job_end = forms.NullBooleanField(
label=_('Type job end'), label=_('On job end'),
required=False, required=False,
widget=BulkEditNullBooleanSelect() widget=BulkEditNullBooleanSelect()
) )

View File

@ -53,7 +53,7 @@ class CustomFieldImportForm(CSVModelForm):
help_text=_('Choice set (for selection fields)') help_text=_('Choice set (for selection fields)')
) )
ui_visibility = CSVChoiceField( ui_visibility = CSVChoiceField(
label=_('Ui visitility'), label=_('UI visibility'),
choices=CustomFieldVisibilityChoices, choices=CustomFieldVisibilityChoices,
help_text=_('How the custom field is displayed in the user interface') help_text=_('How the custom field is displayed in the user interface')
) )

View File

@ -179,7 +179,7 @@ class ImageAttachmentFilterForm(SavedFiltersMixin, FilterForm):
(_('Attributes'), ('content_type_id', 'name',)), (_('Attributes'), ('content_type_id', 'name',)),
) )
content_type_id = ContentTypeChoiceField( content_type_id = ContentTypeChoiceField(
label=_('Content type id'), label=_('Content type'),
queryset=ContentType.objects.filter(FeatureQuery('custom_fields').get_query()), queryset=ContentType.objects.filter(FeatureQuery('custom_fields').get_query()),
required=False required=False
) )

View File

@ -140,7 +140,7 @@ class RoleImportForm(NetBoxModelImportForm):
class PrefixImportForm(NetBoxModelImportForm): class PrefixImportForm(NetBoxModelImportForm):
vrf = CSVModelChoiceField( vrf = CSVModelChoiceField(
label=_('Vrf'), label=_('VRF'),
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -226,7 +226,7 @@ class PrefixImportForm(NetBoxModelImportForm):
class IPRangeImportForm(NetBoxModelImportForm): class IPRangeImportForm(NetBoxModelImportForm):
vrf = CSVModelChoiceField( vrf = CSVModelChoiceField(
label=_('Vrf'), label=_('VRF'),
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -262,7 +262,7 @@ class IPRangeImportForm(NetBoxModelImportForm):
class IPAddressImportForm(NetBoxModelImportForm): class IPAddressImportForm(NetBoxModelImportForm):
vrf = CSVModelChoiceField( vrf = CSVModelChoiceField(
label=_('Vrf'), label=_('VRF'),
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -402,13 +402,13 @@ class VLANGroupImportForm(NetBoxModelImportForm):
min_value=VLAN_VID_MIN, min_value=VLAN_VID_MIN,
max_value=VLAN_VID_MAX, max_value=VLAN_VID_MAX,
required=False, required=False,
label=_('Minimum child VLAN VID (default: {vlan_min})').format(vlan_min=VLAN_VID_MIN) label=_('Minimum child VLAN VID (default: {minimum})').format(minimum=VLAN_VID_MIN)
) )
max_vid = forms.IntegerField( max_vid = forms.IntegerField(
min_value=VLAN_VID_MIN, min_value=VLAN_VID_MIN,
max_value=VLAN_VID_MAX, max_value=VLAN_VID_MAX,
required=False, required=False,
label=_('Maximum child VLAN VID (default: {vlan_min})').format(vlan_min=VLAN_VID_MIN) label=_('Maximum child VLAN VID (default: {maximum})').format(maximum=VLAN_VID_MIN)
) )
class Meta: class Meta:

View File

@ -173,7 +173,6 @@ class PrefixFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
(_('Tenant'), ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
) )
mask_length__lte = forms.IntegerField( mask_length__lte = forms.IntegerField(
label=_('Mask length'),
widget=forms.HiddenInput() widget=forms.HiddenInput()
) )
within_include = forms.CharField( within_include = forms.CharField(

View File

@ -375,7 +375,9 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
if address.version == 6 and address.prefixlen not in (127, 128): if address.version == 6 and address.prefixlen not in (127, 128):
raise ValidationError(msg) raise ValidationError(msg)
if address.version == 4 and address.ip == address.broadcast and address.prefixlen not in (31, 32): if address.version == 4 and address.ip == address.broadcast and address.prefixlen not in (31, 32):
msg = _("{address} is a broadcast address, which may not be assigned to an interface.").format(address=address) msg = _("{address} is a broadcast address, which may not be assigned to an interface.").format(
address=address
)
raise ValidationError(msg) raise ValidationError(msg)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View File

@ -13,8 +13,9 @@ class NumericArrayField(SimpleArrayField):
def clean(self, value): def clean(self, value):
if value and not self.to_python(value): if value and not self.to_python(value):
raise forms.ValidationError(_('Invalid list ({value}). ' raise forms.ValidationError(
'Must be numeric and ranges must be in ascending order').format(value=value)) _("Invalid list ({value}). Must be numeric and ranges must be in ascending order.").format(value=value)
)
return super().clean(value) return super().clean(value)
def to_python(self, value): def to_python(self, value):

View File

@ -21,10 +21,10 @@ class ExpandableNameField(forms.CharField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if not self.help_text: if not self.help_text:
self.help_text = _(""" self.help_text = _(
Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range "Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range are "
are not supported (example: <code>[ge,xe]-0/0/[0-9]</code>). "not supported (example: <code>[ge,xe]-0/0/[0-9]</code>)."
""") )
def to_python(self, value): def to_python(self, value):
if not value: if not value:

View File

@ -64,12 +64,12 @@ class WirelessLANBulkEditForm(NetBoxModelBulkEditForm):
required=False required=False
) )
auth_type = forms.ChoiceField( auth_type = forms.ChoiceField(
label=_('Auth type'), label=_('Authentication type'),
choices=add_blank_choice(WirelessAuthTypeChoices), choices=add_blank_choice(WirelessAuthTypeChoices),
required=False required=False
) )
auth_cipher = forms.ChoiceField( auth_cipher = forms.ChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
choices=add_blank_choice(WirelessAuthCipherChoices), choices=add_blank_choice(WirelessAuthCipherChoices),
required=False required=False
) )
@ -111,12 +111,12 @@ class WirelessLinkBulkEditForm(NetBoxModelBulkEditForm):
required=False required=False
) )
auth_type = forms.ChoiceField( auth_type = forms.ChoiceField(
label=_('Auth type'), label=_('Authentication type'),
choices=add_blank_choice(WirelessAuthTypeChoices), choices=add_blank_choice(WirelessAuthTypeChoices),
required=False required=False
) )
auth_cipher = forms.ChoiceField( auth_cipher = forms.ChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
choices=add_blank_choice(WirelessAuthCipherChoices), choices=add_blank_choice(WirelessAuthCipherChoices),
required=False required=False
) )

View File

@ -59,13 +59,13 @@ class WirelessLANImportForm(NetBoxModelImportForm):
help_text=_('Assigned tenant') help_text=_('Assigned tenant')
) )
auth_type = CSVChoiceField( auth_type = CSVChoiceField(
label=_('Auth type'), label=_('Authentication type'),
choices=WirelessAuthTypeChoices, choices=WirelessAuthTypeChoices,
required=False, required=False,
help_text=_('Authentication type') help_text=_('Authentication type')
) )
auth_cipher = CSVChoiceField( auth_cipher = CSVChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
choices=WirelessAuthCipherChoices, choices=WirelessAuthCipherChoices,
required=False, required=False,
help_text=_('Authentication cipher') help_text=_('Authentication cipher')
@ -86,11 +86,11 @@ class WirelessLinkImportForm(NetBoxModelImportForm):
help_text=_('Connection status') help_text=_('Connection status')
) )
interface_a = CSVModelChoiceField( interface_a = CSVModelChoiceField(
label=_('Interface a'), label=_('Interface A'),
queryset=Interface.objects.all() queryset=Interface.objects.all()
) )
interface_b = CSVModelChoiceField( interface_b = CSVModelChoiceField(
label=_('Interface b'), label=_('Interface B'),
queryset=Interface.objects.all() queryset=Interface.objects.all()
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
@ -101,13 +101,13 @@ class WirelessLinkImportForm(NetBoxModelImportForm):
help_text=_('Assigned tenant') help_text=_('Assigned tenant')
) )
auth_type = CSVChoiceField( auth_type = CSVChoiceField(
label=_('Auth type'), label=_('Authentication type'),
choices=WirelessAuthTypeChoices, choices=WirelessAuthTypeChoices,
required=False, required=False,
help_text=_('Authentication type') help_text=_('Authentication type')
) )
auth_cipher = CSVChoiceField( auth_cipher = CSVChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
choices=WirelessAuthCipherChoices, choices=WirelessAuthCipherChoices,
required=False, required=False,
help_text=_('Authentication cipher') help_text=_('Authentication cipher')

View File

@ -50,17 +50,17 @@ class WirelessLANFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
choices=add_blank_choice(WirelessLANStatusChoices) choices=add_blank_choice(WirelessLANStatusChoices)
) )
auth_type = forms.ChoiceField( auth_type = forms.ChoiceField(
label=_('Auth type'), label=_('Authentication type'),
required=False, required=False,
choices=add_blank_choice(WirelessAuthTypeChoices) choices=add_blank_choice(WirelessAuthTypeChoices)
) )
auth_cipher = forms.ChoiceField( auth_cipher = forms.ChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
required=False, required=False,
choices=add_blank_choice(WirelessAuthCipherChoices) choices=add_blank_choice(WirelessAuthCipherChoices)
) )
auth_psk = forms.CharField( auth_psk = forms.CharField(
label=_('Auth psk'), label=_('Pre-shared key'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -84,17 +84,17 @@ class WirelessLinkFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
choices=add_blank_choice(LinkStatusChoices) choices=add_blank_choice(LinkStatusChoices)
) )
auth_type = forms.ChoiceField( auth_type = forms.ChoiceField(
label=_('Auth type'), label=_('Authentication type'),
required=False, required=False,
choices=add_blank_choice(WirelessAuthTypeChoices) choices=add_blank_choice(WirelessAuthTypeChoices)
) )
auth_cipher = forms.ChoiceField( auth_cipher = forms.ChoiceField(
label=_('Auth cipher'), label=_('Authentication cipher'),
required=False, required=False,
choices=add_blank_choice(WirelessAuthCipherChoices) choices=add_blank_choice(WirelessAuthCipherChoices)
) )
auth_psk = forms.CharField( auth_psk = forms.CharField(
label=_('Auth psk'), label=_('Pre-shared key'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)