13149 add gettext_lazy to forms

This commit is contained in:
Arthur 2023-07-12 22:11:36 +07:00 committed by Jeremy Stretch
parent 05cab09e30
commit e9c553bb7b
4 changed files with 346 additions and 188 deletions

View File

@ -1,5 +1,5 @@
from django import forms from django import forms
from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy as _
from circuits.models import Circuit, CircuitTermination from circuits.models import Circuit, CircuitTermination
from dcim.models import * from dcim.models import *

View File

@ -1,6 +1,6 @@
from django import forms from django import forms
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy as _
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
@ -56,9 +56,11 @@ __all__ = (
class DeviceComponentFilterForm(NetBoxModelFilterSetForm): class DeviceComponentFilterForm(NetBoxModelFilterSetForm):
name = forms.CharField( name = forms.CharField(
label=_('Name'),
required=False required=False
) )
label = forms.CharField( label = forms.CharField(
label=_('Label'),
required=False required=False
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
@ -130,7 +132,7 @@ class RegionFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
model = Region model = Region
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag', 'parent_id')), (None, ('q', 'filter_id', 'tag', 'parent_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')) (_('Contacts'), ('contact', 'contact_role', 'contact_group'))
) )
parent_id = DynamicModelMultipleChoiceField( parent_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -144,7 +146,7 @@ class SiteGroupFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
model = SiteGroup model = SiteGroup
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag', 'parent_id')), (None, ('q', 'filter_id', 'tag', 'parent_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')) (_('Contacts'), ('contact', 'contact_role', 'contact_group'))
) )
parent_id = DynamicModelMultipleChoiceField( parent_id = DynamicModelMultipleChoiceField(
queryset=SiteGroup.objects.all(), queryset=SiteGroup.objects.all(),
@ -158,11 +160,12 @@ class SiteFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
model = Site model = Site
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('status', 'region_id', 'group_id', 'asn_id')), (_('Attributes'), ('status', 'region_id', 'group_id', 'asn_id')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=SiteStatusChoices, choices=SiteStatusChoices,
required=False required=False
) )
@ -188,9 +191,9 @@ class LocationFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelF
model = Location model = Location
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('region_id', 'site_group_id', 'site_id', 'parent_id', 'status')), (_('Attributes'), ('region_id', 'site_group_id', 'site_id', 'parent_id', 'status')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -221,6 +224,7 @@ class LocationFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelF
label=_('Parent') label=_('Parent')
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=LocationStatusChoices, choices=LocationStatusChoices,
required=False required=False
) )
@ -236,12 +240,12 @@ class RackFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
model = Rack model = Rack
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id')),
('Function', ('status', 'role_id')), (_('Function'), ('status', 'role_id')),
('Hardware', ('type', 'width', 'serial', 'asset_tag')), (_('Hardware'), ('type', 'width', 'serial', 'asset_tag')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
('Weight', ('weight', 'max_weight', 'weight_unit')), (_('Weight'), ('weight', 'max_weight', 'weight_unit')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -271,14 +275,17 @@ class RackFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
label=_('Location') label=_('Location')
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=RackStatusChoices, choices=RackStatusChoices,
required=False required=False
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=RackTypeChoices, choices=RackTypeChoices,
required=False required=False
) )
width = forms.MultipleChoiceField( width = forms.MultipleChoiceField(
label=_('Width'),
choices=RackWidthChoices, choices=RackWidthChoices,
required=False required=False
) )
@ -289,21 +296,26 @@ class RackFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
label=_('Role') label=_('Role')
) )
serial = forms.CharField( serial = forms.CharField(
label=_('Serial'),
required=False required=False
) )
asset_tag = forms.CharField( asset_tag = forms.CharField(
label=_('Asset tag'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
weight = forms.DecimalField( weight = forms.DecimalField(
label=_('Weight'),
required=False, required=False,
min_value=1 min_value=1
) )
max_weight = forms.IntegerField( max_weight = forms.IntegerField(
label=_('Max weight'),
required=False, required=False,
min_value=1 min_value=1
) )
weight_unit = forms.ChoiceField( weight_unit = forms.ChoiceField(
label=_('Weight unit'),
choices=add_blank_choice(WeightUnitChoices), choices=add_blank_choice(WeightUnitChoices),
required=False required=False
) )
@ -312,12 +324,12 @@ class RackFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
class RackElevationFilterForm(RackFilterForm): class RackElevationFilterForm(RackFilterForm):
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'id')),
('Function', ('status', 'role_id')), (_('Function'), ('status', 'role_id')),
('Hardware', ('type', 'width', 'serial', 'asset_tag')), (_('Hardware'), ('type', 'width', 'serial', 'asset_tag')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
('Weight', ('weight', 'max_weight', 'weight_unit')), (_('Weight'), ('weight', 'max_weight', 'weight_unit')),
) )
id = DynamicModelMultipleChoiceField( id = DynamicModelMultipleChoiceField(
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
@ -334,9 +346,9 @@ class RackReservationFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
model = RackReservation model = RackReservation
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('User', ('user_id',)), (_('User'), ('user_id',)),
('Rack', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Rack'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -390,7 +402,7 @@ class ManufacturerFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
model = Manufacturer model = Manufacturer
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Contacts', ('contact', 'contact_role', 'contact_group')) (_('Contacts'), ('contact', 'contact_role', 'contact_group'))
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -399,13 +411,13 @@ class DeviceTypeFilterForm(NetBoxModelFilterSetForm):
model = DeviceType model = DeviceType
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Hardware', ('manufacturer_id', 'default_platform_id', 'part_number', 'subdevice_role', 'airflow')), (_('Hardware'), ('manufacturer_id', 'default_platform_id', 'part_number', 'subdevice_role', 'airflow')),
('Images', ('has_front_image', 'has_rear_image')), (_('Images'), ('has_front_image', 'has_rear_image')),
('Components', ( (_('Components'), (
'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces', 'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces',
'pass_through_ports', 'device_bays', 'module_bays', 'inventory_items', 'pass_through_ports', 'device_bays', 'module_bays', 'inventory_items',
)), )),
('Weight', ('weight', 'weight_unit')), (_('Weight'), ('weight', 'weight_unit')),
) )
manufacturer_id = DynamicModelMultipleChoiceField( manufacturer_id = DynamicModelMultipleChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
@ -418,98 +430,103 @@ class DeviceTypeFilterForm(NetBoxModelFilterSetForm):
label=_('Default platform') label=_('Default platform')
) )
part_number = forms.CharField( part_number = forms.CharField(
label=_('Part number'),
required=False required=False
) )
subdevice_role = forms.MultipleChoiceField( subdevice_role = forms.MultipleChoiceField(
label=_('Subdevice role'),
choices=add_blank_choice(SubdeviceRoleChoices), choices=add_blank_choice(SubdeviceRoleChoices),
required=False required=False
) )
airflow = forms.MultipleChoiceField( airflow = forms.MultipleChoiceField(
label=_('Airflow'),
choices=add_blank_choice(DeviceAirflowChoices), choices=add_blank_choice(DeviceAirflowChoices),
required=False required=False
) )
has_front_image = forms.NullBooleanField( has_front_image = forms.NullBooleanField(
required=False, required=False,
label='Has a front image', label=_('Has a front image'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
has_rear_image = forms.NullBooleanField( has_rear_image = forms.NullBooleanField(
required=False, required=False,
label='Has a rear image', label=_('Has a rear image'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
console_ports = forms.NullBooleanField( console_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console ports', label=_('Has console ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
console_server_ports = forms.NullBooleanField( console_server_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console server ports', label=_('Has console server ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_ports = forms.NullBooleanField( power_ports = forms.NullBooleanField(
required=False, required=False,
label='Has power ports', label=_('Has power ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_outlets = forms.NullBooleanField( power_outlets = forms.NullBooleanField(
required=False, required=False,
label='Has power outlets', label=_('Has power outlets'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
interfaces = forms.NullBooleanField( interfaces = forms.NullBooleanField(
required=False, required=False,
label='Has interfaces', label=_('Has interfaces'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
pass_through_ports = forms.NullBooleanField( pass_through_ports = forms.NullBooleanField(
required=False, required=False,
label='Has pass-through ports', label=_('Has pass-through ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
device_bays = forms.NullBooleanField( device_bays = forms.NullBooleanField(
required=False, required=False,
label='Has device bays', label=_('Has device bays'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
module_bays = forms.NullBooleanField( module_bays = forms.NullBooleanField(
required=False, required=False,
label='Has module bays', label=_('Has module bays'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
inventory_items = forms.NullBooleanField( inventory_items = forms.NullBooleanField(
required=False, required=False,
label='Has inventory items', label=_('Has inventory items'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
tag = TagFilterField(model) tag = TagFilterField(model)
weight = forms.DecimalField( weight = forms.DecimalField(
label=_('Weight'),
required=False required=False
) )
weight_unit = forms.ChoiceField( weight_unit = forms.ChoiceField(
label=_('Weight unit'),
choices=add_blank_choice(WeightUnitChoices), choices=add_blank_choice(WeightUnitChoices),
required=False required=False
) )
@ -519,12 +536,12 @@ class ModuleTypeFilterForm(NetBoxModelFilterSetForm):
model = ModuleType model = ModuleType
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Hardware', ('manufacturer_id', 'part_number')), (_('Hardware'), ('manufacturer_id', 'part_number')),
('Components', ( (_('Components'), (
'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces', 'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces',
'pass_through_ports', 'pass_through_ports',
)), )),
('Weight', ('weight', 'weight_unit')), (_('Weight'), ('weight', 'weight_unit')),
) )
manufacturer_id = DynamicModelMultipleChoiceField( manufacturer_id = DynamicModelMultipleChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
@ -533,55 +550,58 @@ class ModuleTypeFilterForm(NetBoxModelFilterSetForm):
fetch_trigger='open' fetch_trigger='open'
) )
part_number = forms.CharField( part_number = forms.CharField(
label=_('Part number'),
required=False required=False
) )
console_ports = forms.NullBooleanField( console_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console ports', label=_('Has console ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
console_server_ports = forms.NullBooleanField( console_server_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console server ports', label=_('Has console server ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_ports = forms.NullBooleanField( power_ports = forms.NullBooleanField(
required=False, required=False,
label='Has power ports', label=_('Has power ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_outlets = forms.NullBooleanField( power_outlets = forms.NullBooleanField(
required=False, required=False,
label='Has power outlets', label=_('Has power outlets'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
interfaces = forms.NullBooleanField( interfaces = forms.NullBooleanField(
required=False, required=False,
label='Has interfaces', label=_('Has interfaces'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
pass_through_ports = forms.NullBooleanField( pass_through_ports = forms.NullBooleanField(
required=False, required=False,
label='Has pass-through ports', label=_('Has pass-through ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
tag = TagFilterField(model) tag = TagFilterField(model)
weight = forms.DecimalField( weight = forms.DecimalField(
label=_('Weight'),
required=False required=False
) )
weight_unit = forms.ChoiceField( weight_unit = forms.ChoiceField(
label=_('Weight unit'),
choices=add_blank_choice(WeightUnitChoices), choices=add_blank_choice(WeightUnitChoices),
required=False required=False
) )
@ -621,15 +641,17 @@ class DeviceFilterForm(
model = Device model = Device
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Operation', ('status', 'role_id', 'airflow', 'serial', 'asset_tag', 'mac_address')), (_('Operation'), ('status', 'role_id', 'airflow', 'serial', 'asset_tag', 'mac_address')),
('Hardware', ('manufacturer_id', 'device_type_id', 'platform_id')), (_('Hardware'), ('manufacturer_id', 'device_type_id', 'platform_id')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
('Components', ( (_('Components'), (
'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces', 'pass_through_ports', 'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces', 'pass_through_ports',
)), )),
('Miscellaneous', ('has_primary_ip', 'has_oob_ip', 'virtual_chassis_member', 'config_template_id', 'local_context_data')) (_('Miscellaneous'), (
'has_primary_ip', 'has_oob_ip', 'virtual_chassis_member', 'config_template_id', 'local_context_data',
))
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -694,22 +716,26 @@ class DeviceFilterForm(
label=_('Platform') label=_('Platform')
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=DeviceStatusChoices, choices=DeviceStatusChoices,
required=False required=False
) )
airflow = forms.MultipleChoiceField( airflow = forms.MultipleChoiceField(
label=_('Airflow'),
choices=add_blank_choice(DeviceAirflowChoices), choices=add_blank_choice(DeviceAirflowChoices),
required=False required=False
) )
serial = forms.CharField( serial = forms.CharField(
label=_('Serial'),
required=False required=False
) )
asset_tag = forms.CharField( asset_tag = forms.CharField(
label=_('Asset tag'),
required=False required=False
) )
mac_address = forms.CharField( mac_address = forms.CharField(
required=False, required=False,
label='MAC address' label=_('MAC address')
) )
config_template_id = DynamicModelMultipleChoiceField( config_template_id = DynamicModelMultipleChoiceField(
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
@ -718,7 +744,7 @@ class DeviceFilterForm(
) )
has_primary_ip = forms.NullBooleanField( has_primary_ip = forms.NullBooleanField(
required=False, required=False,
label='Has a primary IP', label=_('Has a primary IP'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
@ -732,49 +758,49 @@ class DeviceFilterForm(
) )
virtual_chassis_member = forms.NullBooleanField( virtual_chassis_member = forms.NullBooleanField(
required=False, required=False,
label='Virtual chassis member', label=_('Virtual chassis member'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
console_ports = forms.NullBooleanField( console_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console ports', label=_('Has console ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
console_server_ports = forms.NullBooleanField( console_server_ports = forms.NullBooleanField(
required=False, required=False,
label='Has console server ports', label=_('Has console server ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_ports = forms.NullBooleanField( power_ports = forms.NullBooleanField(
required=False, required=False,
label='Has power ports', label=_('Has power ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
power_outlets = forms.NullBooleanField( power_outlets = forms.NullBooleanField(
required=False, required=False,
label='Has power outlets', label=_('Has power outlets'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
interfaces = forms.NullBooleanField( interfaces = forms.NullBooleanField(
required=False, required=False,
label='Has interfaces', label=_('Has interfaces'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
pass_through_ports = forms.NullBooleanField( pass_through_ports = forms.NullBooleanField(
required=False, required=False,
label='Has pass-through ports', label=_('Has pass-through ports'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
@ -789,8 +815,8 @@ class VirtualDeviceContextFilterForm(
model = VirtualDeviceContext model = VirtualDeviceContext
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('device', 'status', 'has_primary_ip')), (_('Attributes'), ('device', 'status', 'has_primary_ip')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
) )
device = DynamicModelMultipleChoiceField( device = DynamicModelMultipleChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
@ -799,12 +825,13 @@ class VirtualDeviceContextFilterForm(
fetch_trigger='open' fetch_trigger='open'
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
required=False, required=False,
choices=add_blank_choice(VirtualDeviceContextStatusChoices) choices=add_blank_choice(VirtualDeviceContextStatusChoices)
) )
has_primary_ip = forms.NullBooleanField( has_primary_ip = forms.NullBooleanField(
required=False, required=False,
label='Has a primary IP', label=_('Has a primary IP'),
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
@ -816,7 +843,7 @@ class ModuleFilterForm(LocalConfigContextFilterForm, TenancyFilterForm, NetBoxMo
model = Module model = Module
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Hardware', ('manufacturer_id', 'module_type_id', 'status', 'serial', 'asset_tag')), (_('Hardware'), ('manufacturer_id', 'module_type_id', 'status', 'serial', 'asset_tag')),
) )
manufacturer_id = DynamicModelMultipleChoiceField( manufacturer_id = DynamicModelMultipleChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
@ -834,13 +861,16 @@ class ModuleFilterForm(LocalConfigContextFilterForm, TenancyFilterForm, NetBoxMo
fetch_trigger='open' fetch_trigger='open'
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=ModuleStatusChoices, choices=ModuleStatusChoices,
required=False required=False
) )
serial = forms.CharField( serial = forms.CharField(
label=_('Serial'),
required=False required=False
) )
asset_tag = forms.CharField( asset_tag = forms.CharField(
label=_('Asset tag'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -850,8 +880,8 @@ class VirtualChassisFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
model = VirtualChassis model = VirtualChassis
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -879,9 +909,9 @@ class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
model = Cable model = Cable
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('site_id', 'location_id', 'rack_id', 'device_id')), (_('Location'), ('site_id', 'location_id', 'rack_id', 'device_id')),
('Attributes', ('type', 'status', 'color', 'length', 'length_unit')), (_('Attributes'), ('type', 'status', 'color', 'length', 'length_unit')),
('Tenant', ('tenant_group_id', 'tenant_id')), (_('Tenant'), ('tenant_group_id', 'tenant_id')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -927,20 +957,25 @@ class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
label=_('Device') label=_('Device')
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=add_blank_choice(CableTypeChoices), choices=add_blank_choice(CableTypeChoices),
required=False required=False
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
required=False, required=False,
choices=add_blank_choice(LinkStatusChoices) choices=add_blank_choice(LinkStatusChoices)
) )
color = ColorField( color = ColorField(
label=_('Color'),
required=False required=False
) )
length = forms.IntegerField( length = forms.IntegerField(
label=_('Length'),
required=False required=False
) )
length_unit = forms.ChoiceField( length_unit = forms.ChoiceField(
label=_('Length unit'),
choices=add_blank_choice(CableLengthUnitChoices), choices=add_blank_choice(CableLengthUnitChoices),
required=False required=False
) )
@ -951,8 +986,8 @@ class PowerPanelFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
model = PowerPanel model = PowerPanel
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id')),
('Contacts', ('contact', 'contact_role', 'contact_group')), (_('Contacts'), ('contact', 'contact_role', 'contact_group')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -989,8 +1024,8 @@ class PowerFeedFilterForm(NetBoxModelFilterSetForm):
model = PowerFeed model = PowerFeed
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Location', ('region_id', 'site_group_id', 'site_id', 'power_panel_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'power_panel_id', 'rack_id')),
('Attributes', ('status', 'type', 'supply', 'phase', 'voltage', 'amperage', 'max_utilization')), (_('Attributes'), ('status', 'type', 'supply', 'phase', 'voltage', 'amperage', 'max_utilization')),
) )
region_id = DynamicModelMultipleChoiceField( region_id = DynamicModelMultipleChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
@ -1029,28 +1064,35 @@ class PowerFeedFilterForm(NetBoxModelFilterSetForm):
label=_('Rack') label=_('Rack')
) )
status = forms.MultipleChoiceField( status = forms.MultipleChoiceField(
label=_('Status'),
choices=PowerFeedStatusChoices, choices=PowerFeedStatusChoices,
required=False required=False
) )
type = forms.ChoiceField( type = forms.ChoiceField(
label=_('Type'),
choices=add_blank_choice(PowerFeedTypeChoices), choices=add_blank_choice(PowerFeedTypeChoices),
required=False required=False
) )
supply = forms.ChoiceField( supply = forms.ChoiceField(
label=_('Supply'),
choices=add_blank_choice(PowerFeedSupplyChoices), choices=add_blank_choice(PowerFeedSupplyChoices),
required=False required=False
) )
phase = forms.ChoiceField( phase = forms.ChoiceField(
label=_('Phase'),
choices=add_blank_choice(PowerFeedPhaseChoices), choices=add_blank_choice(PowerFeedPhaseChoices),
required=False required=False
) )
voltage = forms.IntegerField( voltage = forms.IntegerField(
label=_('Voltage'),
required=False required=False
) )
amperage = forms.IntegerField( amperage = forms.IntegerField(
label=_('Amperage'),
required=False required=False
) )
max_utilization = forms.IntegerField( max_utilization = forms.IntegerField(
label=_('Max utilization'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -1062,12 +1104,14 @@ class PowerFeedFilterForm(NetBoxModelFilterSetForm):
class CabledFilterForm(forms.Form): class CabledFilterForm(forms.Form):
cabled = forms.NullBooleanField( cabled = forms.NullBooleanField(
label=_('Cabled'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
occupied = forms.NullBooleanField( occupied = forms.NullBooleanField(
label=_('Occupied'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
@ -1077,6 +1121,7 @@ class CabledFilterForm(forms.Form):
class PathEndpointFilterForm(CabledFilterForm): class PathEndpointFilterForm(CabledFilterForm):
connected = forms.NullBooleanField( connected = forms.NullBooleanField(
label=_('Connected'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
@ -1088,16 +1133,18 @@ class ConsolePortFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
model = ConsolePort model = ConsolePort
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type', 'speed')), (_('Attributes'), ('name', 'label', 'type', 'speed')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Connection', ('cabled', 'connected', 'occupied')), (_('Connection'), ('cabled', 'connected', 'occupied')),
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=ConsolePortTypeChoices, choices=ConsolePortTypeChoices,
required=False required=False
) )
speed = forms.MultipleChoiceField( speed = forms.MultipleChoiceField(
label=_('Speed'),
choices=ConsolePortSpeedChoices, choices=ConsolePortSpeedChoices,
required=False required=False
) )
@ -1108,16 +1155,18 @@ class ConsoleServerPortFilterForm(PathEndpointFilterForm, DeviceComponentFilterF
model = ConsoleServerPort model = ConsoleServerPort
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type', 'speed')), (_('Attributes'), ('name', 'label', 'type', 'speed')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Connection', ('cabled', 'connected', 'occupied')), (_('Connection'), ('cabled', 'connected', 'occupied')),
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=ConsolePortTypeChoices, choices=ConsolePortTypeChoices,
required=False required=False
) )
speed = forms.MultipleChoiceField( speed = forms.MultipleChoiceField(
label=_('Speed'),
choices=ConsolePortSpeedChoices, choices=ConsolePortSpeedChoices,
required=False required=False
) )
@ -1128,12 +1177,13 @@ class PowerPortFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
model = PowerPort model = PowerPort
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type')), (_('Attributes'), ('name', 'label', 'type')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Connection', ('cabled', 'connected', 'occupied')), (_('Connection'), ('cabled', 'connected', 'occupied')),
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=PowerPortTypeChoices, choices=PowerPortTypeChoices,
required=False required=False
) )
@ -1144,12 +1194,13 @@ class PowerOutletFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
model = PowerOutlet model = PowerOutlet
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type')), (_('Attributes'), ('name', 'label', 'type')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Connection', ('cabled', 'connected', 'occupied')), (_('Connection'), ('cabled', 'connected', 'occupied')),
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=PowerOutletTypeChoices, choices=PowerOutletTypeChoices,
required=False required=False
) )
@ -1160,13 +1211,13 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
model = Interface model = Interface
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'kind', 'type', 'speed', 'duplex', 'enabled', 'mgmt_only')), (_('Attributes'), ('name', 'label', 'kind', 'type', 'speed', 'duplex', 'enabled', 'mgmt_only')),
('Addressing', ('vrf_id', 'l2vpn_id', 'mac_address', 'wwn')), (_('Addressing'), ('vrf_id', 'l2vpn_id', 'mac_address', 'wwn')),
('PoE', ('poe_mode', 'poe_type')), (_('PoE'), ('poe_mode', 'poe_type')),
('Wireless', ('rf_role', 'rf_channel', 'rf_channel_width', 'tx_power')), (_('Wireless'), ('rf_role', 'rf_channel', 'rf_channel_width', 'tx_power')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id', 'vdc_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id', 'vdc_id')),
('Connection', ('cabled', 'connected', 'occupied')), (_('Connection'), ('cabled', 'connected', 'occupied')),
) )
vdc_id = DynamicModelMultipleChoiceField( vdc_id = DynamicModelMultipleChoiceField(
queryset=VirtualDeviceContext.objects.all(), queryset=VirtualDeviceContext.objects.all(),
@ -1177,30 +1228,36 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
label=_('Virtual Device Context') label=_('Virtual Device Context')
) )
kind = forms.MultipleChoiceField( kind = forms.MultipleChoiceField(
label=_('Kind'),
choices=InterfaceKindChoices, choices=InterfaceKindChoices,
required=False required=False
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=InterfaceTypeChoices, choices=InterfaceTypeChoices,
required=False required=False
) )
speed = forms.IntegerField( speed = forms.IntegerField(
label=_('Speed'),
required=False, required=False,
widget=NumberWithOptions( widget=NumberWithOptions(
options=InterfaceSpeedChoices options=InterfaceSpeedChoices
) )
) )
duplex = forms.MultipleChoiceField( duplex = forms.MultipleChoiceField(
label=_('Duplex'),
choices=InterfaceDuplexChoices, choices=InterfaceDuplexChoices,
required=False required=False
) )
enabled = forms.NullBooleanField( enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
) )
) )
mgmt_only = forms.NullBooleanField( mgmt_only = forms.NullBooleanField(
label=_('Mgmt only'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES
@ -1208,50 +1265,50 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
) )
mac_address = forms.CharField( mac_address = forms.CharField(
required=False, required=False,
label='MAC address' label=_('MAC address')
) )
wwn = forms.CharField( wwn = forms.CharField(
required=False, required=False,
label='WWN' label=_('WWN')
) )
poe_mode = forms.MultipleChoiceField( poe_mode = forms.MultipleChoiceField(
choices=InterfacePoEModeChoices, choices=InterfacePoEModeChoices,
required=False, required=False,
label='PoE mode' label=_('PoE mode')
) )
poe_type = forms.MultipleChoiceField( poe_type = forms.MultipleChoiceField(
choices=InterfacePoETypeChoices, choices=InterfacePoETypeChoices,
required=False, required=False,
label='PoE type' label=_('PoE type')
) )
rf_role = forms.MultipleChoiceField( rf_role = forms.MultipleChoiceField(
choices=WirelessRoleChoices, choices=WirelessRoleChoices,
required=False, required=False,
label='Wireless role' label=_('Wireless role')
) )
rf_channel = forms.MultipleChoiceField( rf_channel = forms.MultipleChoiceField(
choices=WirelessChannelChoices, choices=WirelessChannelChoices,
required=False, required=False,
label='Wireless channel' label=_('Wireless channel')
) )
rf_channel_frequency = forms.IntegerField( rf_channel_frequency = forms.IntegerField(
required=False, required=False,
label='Channel frequency (MHz)' label=_('Channel frequency (MHz)')
) )
rf_channel_width = forms.IntegerField( rf_channel_width = forms.IntegerField(
required=False, required=False,
label='Channel width (MHz)' label=_('Channel width (MHz)')
) )
tx_power = forms.IntegerField( tx_power = forms.IntegerField(
required=False, required=False,
label='Transmit power (dBm)', label=_('Transmit power (dBm)'),
min_value=0, min_value=0,
max_value=127 max_value=127
) )
vrf_id = DynamicModelMultipleChoiceField( vrf_id = DynamicModelMultipleChoiceField(
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
required=False, required=False,
label='VRF' label=_('VRF')
) )
l2vpn_id = DynamicModelMultipleChoiceField( l2vpn_id = DynamicModelMultipleChoiceField(
queryset=L2VPN.objects.all(), queryset=L2VPN.objects.all(),
@ -1264,17 +1321,19 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
class FrontPortFilterForm(CabledFilterForm, DeviceComponentFilterForm): class FrontPortFilterForm(CabledFilterForm, DeviceComponentFilterForm):
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type', 'color')), (_('Attributes'), ('name', 'label', 'type', 'color')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Cable', ('cabled', 'occupied')), (_('Cable'), ('cabled', 'occupied')),
) )
model = FrontPort model = FrontPort
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=PortTypeChoices, choices=PortTypeChoices,
required=False required=False
) )
color = ColorField( color = ColorField(
label=_('Color'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -1284,16 +1343,18 @@ class RearPortFilterForm(CabledFilterForm, DeviceComponentFilterForm):
model = RearPort model = RearPort
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'type', 'color')), (_('Attributes'), ('name', 'label', 'type', 'color')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
('Cable', ('cabled', 'occupied')), (_('Cable'), ('cabled', 'occupied')),
) )
type = forms.MultipleChoiceField( type = forms.MultipleChoiceField(
label=_('Type'),
choices=PortTypeChoices, choices=PortTypeChoices,
required=False required=False
) )
color = ColorField( color = ColorField(
label=_('Color'),
required=False required=False
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -1303,12 +1364,13 @@ class ModuleBayFilterForm(DeviceComponentFilterForm):
model = ModuleBay model = ModuleBay
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'position')), (_('Attributes'), ('name', 'label', 'position')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
) )
tag = TagFilterField(model) tag = TagFilterField(model)
position = forms.CharField( position = forms.CharField(
label=_('Position'),
required=False required=False
) )
@ -1317,9 +1379,9 @@ class DeviceBayFilterForm(DeviceComponentFilterForm):
model = DeviceBay model = DeviceBay
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label')), (_('Attributes'), ('name', 'label')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
) )
tag = TagFilterField(model) tag = TagFilterField(model)
@ -1328,9 +1390,9 @@ class InventoryItemFilterForm(DeviceComponentFilterForm):
model = InventoryItem model = InventoryItem
fieldsets = ( fieldsets = (
(None, ('q', 'filter_id', 'tag')), (None, ('q', 'filter_id', 'tag')),
('Attributes', ('name', 'label', 'role_id', 'manufacturer_id', 'serial', 'asset_tag', 'discovered')), (_('Attributes'), ('name', 'label', 'role_id', 'manufacturer_id', 'serial', 'asset_tag', 'discovered')),
('Location', ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')),
('Device', ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')), (_('Device'), ('device_type_id', 'device_role_id', 'device_id', 'virtual_chassis_id')),
) )
role_id = DynamicModelMultipleChoiceField( role_id = DynamicModelMultipleChoiceField(
queryset=InventoryItemRole.objects.all(), queryset=InventoryItemRole.objects.all(),
@ -1344,12 +1406,15 @@ class InventoryItemFilterForm(DeviceComponentFilterForm):
label=_('Manufacturer') label=_('Manufacturer')
) )
serial = forms.CharField( serial = forms.CharField(
label=_('Serial'),
required=False required=False
) )
asset_tag = forms.CharField( asset_tag = forms.CharField(
label=_('Asset tag'),
required=False required=False
) )
discovered = forms.NullBooleanField( discovered = forms.NullBooleanField(
label=_('Discovered'),
required=False, required=False,
widget=forms.Select( widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES choices=BOOLEAN_WITH_BLANK_CHOICES

View File

@ -1,4 +1,5 @@
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _
__all__ = ( __all__ = (
'BaseVCMemberFormSet', 'BaseVCMemberFormSet',
@ -16,6 +17,6 @@ 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 = f"A virtual chassis member already exists in 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

@ -1,7 +1,7 @@
from django import forms from django import forms
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy as _
from timezone_field import TimeZoneFormField from timezone_field import TimeZoneFormField
from dcim.choices import * from dcim.choices import *
@ -70,13 +70,16 @@ __all__ = (
class RegionForm(NetBoxModelForm): class RegionForm(NetBoxModelForm):
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
label=_('Parent'),
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False required=False
) )
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Region', ( (_('Region'), (
'parent', 'name', 'slug', 'description', 'tags', 'parent', 'name', 'slug', 'description', 'tags',
)), )),
) )
@ -90,13 +93,16 @@ class RegionForm(NetBoxModelForm):
class SiteGroupForm(NetBoxModelForm): class SiteGroupForm(NetBoxModelForm):
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
label=_('Parent'),
queryset=SiteGroup.objects.all(), queryset=SiteGroup.objects.all(),
required=False required=False
) )
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Site Group', ( (_('Site Group'), (
'parent', 'name', 'slug', 'description', 'tags', 'parent', 'name', 'slug', 'description', 'tags',
)), )),
) )
@ -110,10 +116,12 @@ class SiteGroupForm(NetBoxModelForm):
class SiteForm(TenancyForm, NetBoxModelForm): class SiteForm(TenancyForm, NetBoxModelForm):
region = DynamicModelChoiceField( region = DynamicModelChoiceField(
label=_('Region'),
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False required=False
) )
group = DynamicModelChoiceField( group = DynamicModelChoiceField(
label=_('Group'),
queryset=SiteGroup.objects.all(), queryset=SiteGroup.objects.all(),
required=False required=False
) )
@ -122,19 +130,24 @@ class SiteForm(TenancyForm, NetBoxModelForm):
label=_('ASNs'), label=_('ASNs'),
required=False required=False
) )
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
time_zone = TimeZoneFormField( time_zone = TimeZoneFormField(
label=_('Time zone'),
choices=add_blank_choice(TimeZoneFormField().choices), choices=add_blank_choice(TimeZoneFormField().choices),
required=False required=False
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
fieldsets = ( fieldsets = (
('Site', ( (_('Site'), (
'name', 'slug', 'status', 'region', 'group', 'facility', 'asns', 'time_zone', 'description', 'tags', 'name', 'slug', 'status', 'region', 'group', 'facility', 'asns', 'time_zone', 'description', 'tags',
)), )),
('Tenancy', ('tenant_group', 'tenant')), (_('Tenancy'), ('tenant_group', 'tenant')),
('Contact Info', ('physical_address', 'shipping_address', 'latitude', 'longitude')), (_('Contact Info'), ('physical_address', 'shipping_address', 'latitude', 'longitude')),
) )
class Meta: class Meta:
@ -159,10 +172,12 @@ class SiteForm(TenancyForm, NetBoxModelForm):
class LocationForm(TenancyForm, NetBoxModelForm): class LocationForm(TenancyForm, NetBoxModelForm):
site = DynamicModelChoiceField( site = DynamicModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
selector=True selector=True
) )
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
label=_('Parent'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -172,8 +187,8 @@ class LocationForm(TenancyForm, NetBoxModelForm):
slug = SlugField() slug = SlugField()
fieldsets = ( fieldsets = (
('Location', ('site', 'parent', 'name', 'slug', 'status', 'description', 'tags')), (_('Location'), ('site', 'parent', 'name', 'slug', 'status', 'description', 'tags')),
('Tenancy', ('tenant_group', 'tenant')), (_('Tenancy'), ('tenant_group', 'tenant')),
) )
class Meta: class Meta:
@ -184,10 +199,12 @@ class LocationForm(TenancyForm, NetBoxModelForm):
class RackRoleForm(NetBoxModelForm): class RackRoleForm(NetBoxModelForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Rack Role', ( (_('Rack Role'), (
'name', 'slug', 'color', 'description', 'tags', 'name', 'slug', 'color', 'description', 'tags',
)), )),
) )
@ -201,10 +218,12 @@ class RackRoleForm(NetBoxModelForm):
class RackForm(TenancyForm, NetBoxModelForm): class RackForm(TenancyForm, NetBoxModelForm):
site = DynamicModelChoiceField( site = DynamicModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
selector=True selector=True
) )
location = DynamicModelChoiceField( location = DynamicModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -212,10 +231,13 @@ class RackForm(TenancyForm, NetBoxModelForm):
} }
) )
role = DynamicModelChoiceField( role = DynamicModelChoiceField(
label=_('Role'),
queryset=RackRole.objects.all(), queryset=RackRole.objects.all(),
required=False required=False
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
class Meta: class Meta:
model = Rack model = Rack
@ -228,14 +250,17 @@ class RackForm(TenancyForm, NetBoxModelForm):
class RackReservationForm(TenancyForm, NetBoxModelForm): class RackReservationForm(TenancyForm, NetBoxModelForm):
rack = DynamicModelChoiceField( rack = DynamicModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
selector=True selector=True
) )
units = NumericArrayField( units = NumericArrayField(
label=_('Units'),
base_field=forms.IntegerField(), base_field=forms.IntegerField(),
help_text=_("Comma-separated list of numeric unit IDs. A range may be specified using a hyphen.") help_text=_("Comma-separated list of numeric unit IDs. A range may be specified using a hyphen.")
) )
user = forms.ModelChoiceField( user = forms.ModelChoiceField(
label=_('User'),
queryset=get_user_model().objects.order_by( queryset=get_user_model().objects.order_by(
'username' 'username'
) )
@ -243,8 +268,8 @@ class RackReservationForm(TenancyForm, NetBoxModelForm):
comments = CommentField() comments = CommentField()
fieldsets = ( fieldsets = (
('Reservation', ('rack', 'units', 'user', 'description', 'tags')), (_('Reservation'), ('rack', 'units', 'user', 'description', 'tags')),
('Tenancy', ('tenant_group', 'tenant')), (_('Tenancy'), ('tenant_group', 'tenant')),
) )
class Meta: class Meta:
@ -255,10 +280,12 @@ class RackReservationForm(TenancyForm, NetBoxModelForm):
class ManufacturerForm(NetBoxModelForm): class ManufacturerForm(NetBoxModelForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Manufacturer', ( (_('Manufacturer'), (
'name', 'slug', 'description', 'tags', 'name', 'slug', 'description', 'tags',
)), )),
) )
@ -272,23 +299,28 @@ class ManufacturerForm(NetBoxModelForm):
class DeviceTypeForm(NetBoxModelForm): class DeviceTypeForm(NetBoxModelForm):
manufacturer = DynamicModelChoiceField( manufacturer = DynamicModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all() queryset=Manufacturer.objects.all()
) )
default_platform = DynamicModelChoiceField( default_platform = DynamicModelChoiceField(
label=_('Default platform'),
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
required=False required=False
) )
slug = SlugField( slug = SlugField(
label=_('Slug'),
slug_source='model' slug_source='model'
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
fieldsets = ( fieldsets = (
('Device Type', ('manufacturer', 'model', 'slug', 'default_platform', 'description', 'tags')), (_('Device Type'), ('manufacturer', 'model', 'slug', 'default_platform', 'description', 'tags')),
('Chassis', ( (_('Chassis'), (
'u_height', 'is_full_depth', 'part_number', 'subdevice_role', 'airflow', 'weight', 'weight_unit', 'u_height', 'is_full_depth', 'part_number', 'subdevice_role', 'airflow', 'weight', 'weight_unit',
)), )),
('Images', ('front_image', 'rear_image')), (_('Images'), ('front_image', 'rear_image')),
) )
class Meta: class Meta:
@ -310,13 +342,16 @@ class DeviceTypeForm(NetBoxModelForm):
class ModuleTypeForm(NetBoxModelForm): class ModuleTypeForm(NetBoxModelForm):
manufacturer = DynamicModelChoiceField( manufacturer = DynamicModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all() queryset=Manufacturer.objects.all()
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
fieldsets = ( fieldsets = (
('Module Type', ('manufacturer', 'model', 'part_number', 'description', 'tags')), (_('Module Type'), ('manufacturer', 'model', 'part_number', 'description', 'tags')),
('Weight', ('weight', 'weight_unit')) (_('Weight'), ('weight', 'weight_unit'))
) )
class Meta: class Meta:
@ -328,13 +363,16 @@ class ModuleTypeForm(NetBoxModelForm):
class DeviceRoleForm(NetBoxModelForm): class DeviceRoleForm(NetBoxModelForm):
config_template = DynamicModelChoiceField( config_template = DynamicModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
required=False required=False
) )
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Device Role', ( (_('Device Role'), (
'name', 'slug', 'color', 'vm_role', 'config_template', 'description', 'tags', 'name', 'slug', 'color', 'vm_role', 'config_template', 'description', 'tags',
)), )),
) )
@ -348,19 +386,22 @@ class DeviceRoleForm(NetBoxModelForm):
class PlatformForm(NetBoxModelForm): class PlatformForm(NetBoxModelForm):
manufacturer = DynamicModelChoiceField( manufacturer = DynamicModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
required=False required=False
) )
config_template = DynamicModelChoiceField( config_template = DynamicModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
required=False required=False
) )
slug = SlugField( slug = SlugField(
label=_('Slug'),
max_length=64 max_length=64
) )
fieldsets = ( fieldsets = (
('Platform', ('name', 'slug', 'manufacturer', 'config_template', 'description', 'tags')), (_('Platform'), ('name', 'slug', 'manufacturer', 'config_template', 'description', 'tags')),
) )
class Meta: class Meta:
@ -372,10 +413,12 @@ class PlatformForm(NetBoxModelForm):
class DeviceForm(TenancyForm, NetBoxModelForm): class DeviceForm(TenancyForm, NetBoxModelForm):
site = DynamicModelChoiceField( site = DynamicModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
selector=True selector=True
) )
location = DynamicModelChoiceField( location = DynamicModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -386,6 +429,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
} }
) )
rack = DynamicModelChoiceField( rack = DynamicModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -394,6 +438,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
} }
) )
position = forms.DecimalField( position = forms.DecimalField(
label=_('Position'),
required=False, required=False,
help_text=_("The lowest-numbered unit occupied by the device"), help_text=_("The lowest-numbered unit occupied by the device"),
widget=APISelect( widget=APISelect(
@ -405,27 +450,34 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
) )
) )
device_type = DynamicModelChoiceField( device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all(), queryset=DeviceType.objects.all(),
selector=True selector=True
) )
device_role = DynamicModelChoiceField( device_role = DynamicModelChoiceField(
label=_('Device role'),
queryset=DeviceRole.objects.all() queryset=DeviceRole.objects.all()
) )
platform = DynamicModelChoiceField( platform = DynamicModelChoiceField(
label=_('Platform'),
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
required=False required=False
) )
cluster = DynamicModelChoiceField( cluster = DynamicModelChoiceField(
label=_('Cluster'),
queryset=Cluster.objects.all(), queryset=Cluster.objects.all(),
required=False, required=False,
selector=True selector=True
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
local_context_data = JSONField( local_context_data = JSONField(
required=False, required=False,
label='' label=''
) )
virtual_chassis = DynamicModelChoiceField( virtual_chassis = DynamicModelChoiceField(
label=_('Virtual chassis'),
queryset=VirtualChassis.objects.all(), queryset=VirtualChassis.objects.all(),
required=False, required=False,
selector=True selector=True
@ -441,6 +493,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
help_text=_("The priority of the device in the virtual chassis") help_text=_("The priority of the device in the virtual chassis")
) )
config_template = DynamicModelChoiceField( config_template = DynamicModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
required=False required=False
) )
@ -518,36 +571,43 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
class ModuleForm(ModuleCommonForm, NetBoxModelForm): class ModuleForm(ModuleCommonForm, NetBoxModelForm):
device = DynamicModelChoiceField( device = DynamicModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
initial_params={ initial_params={
'modulebays': '$module_bay' 'modulebays': '$module_bay'
} }
) )
module_bay = DynamicModelChoiceField( module_bay = DynamicModelChoiceField(
label=_('Module bay'),
queryset=ModuleBay.objects.all(), queryset=ModuleBay.objects.all(),
query_params={ query_params={
'device_id': '$device' 'device_id': '$device'
} }
) )
module_type = DynamicModelChoiceField( module_type = DynamicModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(), queryset=ModuleType.objects.all(),
selector=True selector=True
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
replicate_components = forms.BooleanField( replicate_components = forms.BooleanField(
label=_('Replicate components'),
required=False, required=False,
initial=True, initial=True,
help_text=_("Automatically populate components associated with this module type") help_text=_("Automatically populate components associated with this module type")
) )
adopt_components = forms.BooleanField( adopt_components = forms.BooleanField(
label=_('Adopt components'),
required=False, required=False,
initial=False, initial=False,
help_text=_("Adopt already existing components") help_text=_("Adopt already existing components")
) )
fieldsets = ( fieldsets = (
('Module', ('device', 'module_bay', 'module_type', 'status', 'description', 'tags')), (_('Module'), ('device', 'module_bay', 'module_type', 'status', 'description', 'tags')),
('Hardware', ( (_('Hardware'), (
'serial', 'asset_tag', 'replicate_components', 'adopt_components', 'serial', 'asset_tag', 'replicate_components', 'adopt_components',
)), )),
) )
@ -571,7 +631,9 @@ class ModuleForm(ModuleCommonForm, NetBoxModelForm):
class CableForm(TenancyForm, NetBoxModelForm): class CableForm(TenancyForm, NetBoxModelForm):
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
class Meta: class Meta:
model = Cable model = Cable
@ -581,17 +643,19 @@ class CableForm(TenancyForm, NetBoxModelForm):
] ]
error_messages = { error_messages = {
'length': { 'length': {
'max_value': 'Maximum length is 32767 (any unit)' 'max_value': _('Maximum length is 32767 (any unit)')
} }
} }
class PowerPanelForm(NetBoxModelForm): class PowerPanelForm(NetBoxModelForm):
site = DynamicModelChoiceField( site = DynamicModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
selector=True selector=True
) )
location = DynamicModelChoiceField( location = DynamicModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -613,19 +677,23 @@ class PowerPanelForm(NetBoxModelForm):
class PowerFeedForm(NetBoxModelForm): class PowerFeedForm(NetBoxModelForm):
power_panel = DynamicModelChoiceField( power_panel = DynamicModelChoiceField(
label=_('Power panel'),
queryset=PowerPanel.objects.all(), queryset=PowerPanel.objects.all(),
selector=True selector=True
) )
rack = DynamicModelChoiceField( rack = DynamicModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
required=False, required=False,
selector=True selector=True
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
fieldsets = ( fieldsets = (
('Power Feed', ('power_panel', 'rack', 'name', 'status', 'type', 'description', 'mark_connected', 'tags')), (_('Power Feed'), ('power_panel', 'rack', 'name', 'status', 'type', 'description', 'mark_connected', 'tags')),
('Characteristics', ('supply', 'voltage', 'amperage', 'phase', 'max_utilization')), (_('Characteristics'), ('supply', 'voltage', 'amperage', 'phase', 'max_utilization')),
) )
class Meta: class Meta:
@ -642,10 +710,13 @@ class PowerFeedForm(NetBoxModelForm):
class VirtualChassisForm(NetBoxModelForm): class VirtualChassisForm(NetBoxModelForm):
master = forms.ModelChoiceField( master = forms.ModelChoiceField(
label=_('Master'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
) )
comments = CommentField() comments = CommentField(
label=_('Comments'),
)
class Meta: class Meta:
model = VirtualChassis model = VirtualChassis
@ -705,6 +776,7 @@ class DeviceVCMembershipForm(forms.ModelForm):
class VCMemberSelectForm(BootstrapMixin, forms.Form): class VCMemberSelectForm(BootstrapMixin, forms.Form):
device = DynamicModelChoiceField( device = DynamicModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
query_params={ query_params={
'virtual_chassis_id': 'null', 'virtual_chassis_id': 'null',
@ -727,6 +799,7 @@ class VCMemberSelectForm(BootstrapMixin, forms.Form):
class ComponentTemplateForm(BootstrapMixin, forms.ModelForm): class ComponentTemplateForm(BootstrapMixin, forms.ModelForm):
device_type = DynamicModelChoiceField( device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all() queryset=DeviceType.objects.all()
) )
@ -740,10 +813,12 @@ class ComponentTemplateForm(BootstrapMixin, forms.ModelForm):
class ModularComponentTemplateForm(ComponentTemplateForm): class ModularComponentTemplateForm(ComponentTemplateForm):
device_type = DynamicModelChoiceField( device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all().all(), queryset=DeviceType.objects.all().all(),
required=False required=False
) )
module_type = DynamicModelChoiceField( module_type = DynamicModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(), queryset=ModuleType.objects.all(),
required=False required=False
) )
@ -796,6 +871,7 @@ class PowerPortTemplateForm(ModularComponentTemplateForm):
class PowerOutletTemplateForm(ModularComponentTemplateForm): class PowerOutletTemplateForm(ModularComponentTemplateForm):
power_port = DynamicModelChoiceField( power_port = DynamicModelChoiceField(
label=_('Power port'),
queryset=PowerPortTemplate.objects.all(), queryset=PowerPortTemplate.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -816,6 +892,7 @@ class PowerOutletTemplateForm(ModularComponentTemplateForm):
class InterfaceTemplateForm(ModularComponentTemplateForm): class InterfaceTemplateForm(ModularComponentTemplateForm):
bridge = DynamicModelChoiceField( bridge = DynamicModelChoiceField(
label=_('Bridge'),
queryset=InterfaceTemplate.objects.all(), queryset=InterfaceTemplate.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -826,8 +903,8 @@ class InterfaceTemplateForm(ModularComponentTemplateForm):
fieldsets = ( fieldsets = (
(None, ('device_type', 'module_type', 'name', 'label', 'type', 'enabled', 'mgmt_only', 'description', 'bridge')), (None, ('device_type', 'module_type', 'name', 'label', 'type', 'enabled', 'mgmt_only', 'description', 'bridge')),
('PoE', ('poe_mode', 'poe_type')), (_('PoE'), ('poe_mode', 'poe_type')),
('Wireless', ('rf_role',)) (_('Wireless'), ('rf_role',)),
) )
class Meta: class Meta:
@ -839,6 +916,7 @@ class InterfaceTemplateForm(ModularComponentTemplateForm):
class FrontPortTemplateForm(ModularComponentTemplateForm): class FrontPortTemplateForm(ModularComponentTemplateForm):
rear_port = DynamicModelChoiceField( rear_port = DynamicModelChoiceField(
label=_('Rear port'),
queryset=RearPortTemplate.objects.all(), queryset=RearPortTemplate.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -900,6 +978,7 @@ class DeviceBayTemplateForm(ComponentTemplateForm):
class InventoryItemTemplateForm(ComponentTemplateForm): class InventoryItemTemplateForm(ComponentTemplateForm):
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
label=_('Parent'),
queryset=InventoryItemTemplate.objects.all(), queryset=InventoryItemTemplate.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -907,20 +986,24 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
} }
) )
role = DynamicModelChoiceField( role = DynamicModelChoiceField(
label=_('Role'),
queryset=InventoryItemRole.objects.all(), queryset=InventoryItemRole.objects.all(),
required=False required=False
) )
manufacturer = DynamicModelChoiceField( manufacturer = DynamicModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
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
) )
@ -946,6 +1029,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
class DeviceComponentForm(NetBoxModelForm): class DeviceComponentForm(NetBoxModelForm):
device = DynamicModelChoiceField( device = DynamicModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
selector=True selector=True
) )
@ -960,6 +1044,7 @@ class DeviceComponentForm(NetBoxModelForm):
class ModularDeviceComponentForm(DeviceComponentForm): class ModularDeviceComponentForm(DeviceComponentForm):
module = DynamicModelChoiceField( module = DynamicModelChoiceField(
label=_('Module'),
queryset=Module.objects.all(), queryset=Module.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -1016,6 +1101,7 @@ class PowerPortForm(ModularDeviceComponentForm):
class PowerOutletForm(ModularDeviceComponentForm): class PowerOutletForm(ModularDeviceComponentForm):
power_port = DynamicModelChoiceField( power_port = DynamicModelChoiceField(
label=_('Power port'),
queryset=PowerPort.objects.all(), queryset=PowerPort.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -1042,7 +1128,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',
} }
@ -1120,13 +1206,13 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
) )
fieldsets = ( fieldsets = (
('Interface', ('device', 'module', 'name', 'label', 'type', 'speed', 'duplex', 'description', 'tags')), (_('Interface'), ('device', 'module', 'name', 'label', 'type', 'speed', 'duplex', 'description', 'tags')),
('Addressing', ('vrf', 'mac_address', 'wwn')), (_('Addressing'), ('vrf', 'mac_address', 'wwn')),
('Operation', ('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected')), (_('Operation'), ('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected')),
('Related Interfaces', ('parent', 'bridge', 'lag')), (_('Related Interfaces'), ('parent', 'bridge', 'lag')),
('PoE', ('poe_mode', 'poe_type')), (_('PoE'), ('poe_mode', 'poe_type')),
('802.1Q Switching', ('mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans')), (_('802.1Q Switching'), ('mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans')),
('Wireless', ( (_('Wireless'), (
'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'wireless_lan_group', 'wireless_lans', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'wireless_lan_group', 'wireless_lans',
)), )),
) )
@ -1232,6 +1318,7 @@ class PopulateDeviceBayForm(BootstrapMixin, forms.Form):
class InventoryItemForm(DeviceComponentForm): class InventoryItemForm(DeviceComponentForm):
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
label=_('Parent'),
queryset=InventoryItem.objects.all(), queryset=InventoryItem.objects.all(),
required=False, required=False,
query_params={ query_params={
@ -1239,10 +1326,12 @@ class InventoryItemForm(DeviceComponentForm):
} }
) )
role = DynamicModelChoiceField( role = DynamicModelChoiceField(
label=_('Role'),
queryset=InventoryItemRole.objects.all(), queryset=InventoryItemRole.objects.all(),
required=False required=False
) )
manufacturer = DynamicModelChoiceField( manufacturer = DynamicModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
required=False required=False
) )
@ -1306,8 +1395,8 @@ class InventoryItemForm(DeviceComponentForm):
) )
fieldsets = ( fieldsets = (
('Inventory Item', ('device', 'parent', 'name', 'label', 'role', 'description', 'tags')), (_('Inventory Item'), ('device', 'parent', 'name', 'label', 'role', 'description', 'tags')),
('Hardware', ('manufacturer', 'part_id', 'serial', 'asset_tag')), (_('Hardware'), ('manufacturer', 'part_id', 'serial', 'asset_tag')),
) )
class Meta: class Meta:
@ -1358,7 +1447,7 @@ class InventoryItemForm(DeviceComponentForm):
) if self.cleaned_data[field] ) if self.cleaned_data[field]
] ]
if len(selected_objects) > 1: if len(selected_objects) > 1:
raise forms.ValidationError("An InventoryItem can only be assigned to a single component.") raise forms.ValidationError(_("An InventoryItem can only be assigned to a single component."))
elif selected_objects: elif selected_objects:
self.instance.component = self.cleaned_data[selected_objects[0]] self.instance.component = self.cleaned_data[selected_objects[0]]
else: else:
@ -1369,10 +1458,12 @@ class InventoryItemForm(DeviceComponentForm):
# #
class InventoryItemRoleForm(NetBoxModelForm): class InventoryItemRoleForm(NetBoxModelForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
fieldsets = ( fieldsets = (
('Inventory Item Role', ( (_('Inventory Item Role'), (
'name', 'slug', 'color', 'description', 'tags', 'name', 'slug', 'color', 'description', 'tags',
)), )),
) )
@ -1386,12 +1477,13 @@ class InventoryItemRoleForm(NetBoxModelForm):
class VirtualDeviceContextForm(TenancyForm, NetBoxModelForm): class VirtualDeviceContextForm(TenancyForm, NetBoxModelForm):
device = DynamicModelChoiceField( device = DynamicModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
selector=True selector=True
) )
primary_ip4 = DynamicModelChoiceField( primary_ip4 = DynamicModelChoiceField(
queryset=IPAddress.objects.all(), queryset=IPAddress.objects.all(),
label='Primary IPv4', label=_('Primary IPv4'),
required=False, required=False,
query_params={ query_params={
'device_id': '$device', 'device_id': '$device',
@ -1400,7 +1492,7 @@ class VirtualDeviceContextForm(TenancyForm, NetBoxModelForm):
) )
primary_ip6 = DynamicModelChoiceField( primary_ip6 = DynamicModelChoiceField(
queryset=IPAddress.objects.all(), queryset=IPAddress.objects.all(),
label='Primary IPv6', label=_('Primary IPv6'),
required=False, required=False,
query_params={ query_params={
'device_id': '$device', 'device_id': '$device',
@ -1409,8 +1501,8 @@ class VirtualDeviceContextForm(TenancyForm, NetBoxModelForm):
) )
fieldsets = ( fieldsets = (
('Virtual Device Context', ('device', 'name', 'status', 'identifier', 'primary_ip4', 'primary_ip6', 'tags')), (_('Virtual Device Context'), ('device', 'name', 'status', 'identifier', 'primary_ip4', 'primary_ip6', 'tags')),
('Tenancy', ('tenant_group', 'tenant')) (_('Tenancy'), ('tenant_group', 'tenant'))
) )
class Meta: class Meta: