13149 add gettext_lazy to forms

This commit is contained in:
Arthur 2023-07-12 17:42:59 +07:00 committed by Jeremy Stretch
parent 5f5b332a65
commit 05cab09e30
4 changed files with 346 additions and 51 deletions

View File

@ -1,7 +1,7 @@
from django import forms from django import forms
from dcim.models import * from dcim.models import *
from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy as _
from extras.forms import CustomFieldsMixin from extras.forms import CustomFieldsMixin
from extras.models import Tag from extras.models import Tag
from utilities.forms import BootstrapMixin, form_from_model from utilities.forms import BootstrapMixin, form_from_model
@ -28,14 +28,17 @@ __all__ = (
class DeviceBulkAddComponentForm(BootstrapMixin, CustomFieldsMixin, ComponentCreateForm): class DeviceBulkAddComponentForm(BootstrapMixin, CustomFieldsMixin, ComponentCreateForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
label=_('Pk'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
widget=forms.MultipleHiddenInput() widget=forms.MultipleHiddenInput()
) )
description = forms.CharField( description = forms.CharField(
label=_('Description'),
max_length=100, max_length=100,
required=False required=False
) )
tags = DynamicModelMultipleChoiceField( tags = DynamicModelMultipleChoiceField(
label=_('Tags'),
queryset=Tag.objects.all(), queryset=Tag.objects.all(),
required=False required=False
) )

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.forms.array import SimpleArrayField from django.contrib.postgres.forms.array import SimpleArrayField
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
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,6 +56,7 @@ __all__ = (
class RegionImportForm(NetBoxModelImportForm): class RegionImportForm(NetBoxModelImportForm):
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -69,6 +70,7 @@ class RegionImportForm(NetBoxModelImportForm):
class SiteGroupImportForm(NetBoxModelImportForm): class SiteGroupImportForm(NetBoxModelImportForm):
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=SiteGroup.objects.all(), queryset=SiteGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -82,22 +84,26 @@ class SiteGroupImportForm(NetBoxModelImportForm):
class SiteImportForm(NetBoxModelImportForm): class SiteImportForm(NetBoxModelImportForm):
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=SiteStatusChoices, choices=SiteStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
region = CSVModelChoiceField( region = CSVModelChoiceField(
label=_('Region'),
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Assigned region') help_text=_('Assigned region')
) )
group = CSVModelChoiceField( group = CSVModelChoiceField(
label=_('Group'),
queryset=SiteGroup.objects.all(), queryset=SiteGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Assigned group') help_text=_('Assigned group')
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -119,11 +125,13 @@ class SiteImportForm(NetBoxModelImportForm):
class LocationImportForm(NetBoxModelImportForm): class LocationImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Assigned site') help_text=_('Assigned site')
) )
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -133,10 +141,12 @@ class LocationImportForm(NetBoxModelImportForm):
} }
) )
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=LocationStatusChoices, choices=LocationStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -149,7 +159,9 @@ class LocationImportForm(NetBoxModelImportForm):
class RackRoleImportForm(NetBoxModelImportForm): class RackRoleImportForm(NetBoxModelImportForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
class Meta: class Meta:
model = RackRole model = RackRole
@ -161,45 +173,54 @@ class RackRoleImportForm(NetBoxModelImportForm):
class RackImportForm(NetBoxModelImportForm): class RackImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name' to_field_name='name'
) )
location = CSVModelChoiceField( location = CSVModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
to_field_name='name' to_field_name='name'
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Name of assigned tenant') help_text=_('Name of assigned tenant')
) )
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=RackStatusChoices, choices=RackStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
role = CSVModelChoiceField( role = CSVModelChoiceField(
label=_('Role'),
queryset=RackRole.objects.all(), queryset=RackRole.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Name of assigned role') help_text=_('Name of assigned role')
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=RackTypeChoices, choices=RackTypeChoices,
required=False, required=False,
help_text=_('Rack type') help_text=_('Rack type')
) )
width = forms.ChoiceField( width = forms.ChoiceField(
label=_('Width'),
choices=RackWidthChoices, choices=RackWidthChoices,
help_text=_('Rail-to-rail width (in inches)') help_text=_('Rail-to-rail width (in inches)')
) )
outer_unit = CSVChoiceField( outer_unit = CSVChoiceField(
label=_('Outer unit'),
choices=RackDimensionUnitChoices, choices=RackDimensionUnitChoices,
required=False, required=False,
help_text=_('Unit for outer dimensions') help_text=_('Unit for outer dimensions')
) )
weight_unit = CSVChoiceField( weight_unit = CSVChoiceField(
label=_('Weight unit'),
choices=WeightUnitChoices, choices=WeightUnitChoices,
required=False, required=False,
help_text=_('Unit for rack weights') help_text=_('Unit for rack weights')
@ -225,27 +246,32 @@ class RackImportForm(NetBoxModelImportForm):
class RackReservationImportForm(NetBoxModelImportForm): class RackReservationImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Parent site') help_text=_('Parent site')
) )
location = CSVModelChoiceField( location = CSVModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_("Rack's location (if any)") help_text=_("Rack's location (if any)")
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Rack') help_text=_('Rack')
) )
units = SimpleArrayField( units = SimpleArrayField(
label=_('Units'),
base_field=forms.IntegerField(), base_field=forms.IntegerField(),
required=True, required=True,
help_text=_('Comma-separated list of individual unit numbers') help_text=_('Comma-separated list of individual unit numbers')
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -282,21 +308,25 @@ class ManufacturerImportForm(NetBoxModelImportForm):
class DeviceTypeImportForm(NetBoxModelImportForm): class DeviceTypeImportForm(NetBoxModelImportForm):
manufacturer = forms.ModelChoiceField( manufacturer = forms.ModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('The manufacturer which produces this device type') help_text=_('The manufacturer which produces this device type')
) )
default_platform = forms.ModelChoiceField( default_platform = forms.ModelChoiceField(
label=_('Default platform'),
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('The default platform for devices of this type (optional)') help_text=_('The default platform for devices of this type (optional)')
) )
weight = forms.DecimalField( weight = forms.DecimalField(
label=_('Weight'),
required=False, required=False,
help_text=_('Device weight'), help_text=_('Device weight'),
) )
weight_unit = CSVChoiceField( weight_unit = CSVChoiceField(
label=_('Weight unit'),
choices=WeightUnitChoices, choices=WeightUnitChoices,
required=False, required=False,
help_text=_('Unit for device weight') help_text=_('Unit for device weight')
@ -312,14 +342,17 @@ class DeviceTypeImportForm(NetBoxModelImportForm):
class ModuleTypeImportForm(NetBoxModelImportForm): class ModuleTypeImportForm(NetBoxModelImportForm):
manufacturer = forms.ModelChoiceField( manufacturer = forms.ModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name' to_field_name='name'
) )
weight = forms.DecimalField( weight = forms.DecimalField(
label=_('Weight'),
required=False, required=False,
help_text=_('Module weight'), help_text=_('Module weight'),
) )
weight_unit = CSVChoiceField( weight_unit = CSVChoiceField(
label=_('Weight unit'),
choices=WeightUnitChoices, choices=WeightUnitChoices,
required=False, required=False,
help_text=_('Unit for module weight') help_text=_('Unit for module weight')
@ -332,6 +365,7 @@ class ModuleTypeImportForm(NetBoxModelImportForm):
class DeviceRoleImportForm(NetBoxModelImportForm): class DeviceRoleImportForm(NetBoxModelImportForm):
config_template = CSVModelChoiceField( config_template = CSVModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -348,14 +382,18 @@ class DeviceRoleImportForm(NetBoxModelImportForm):
class PlatformImportForm(NetBoxModelImportForm): class PlatformImportForm(NetBoxModelImportForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
manufacturer = CSVModelChoiceField( manufacturer = CSVModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Limit platform assignments to this manufacturer') help_text=_('Limit platform assignments to this manufacturer')
) )
config_template = CSVModelChoiceField( config_template = CSVModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -371,43 +409,51 @@ class PlatformImportForm(NetBoxModelImportForm):
class BaseDeviceImportForm(NetBoxModelImportForm): class BaseDeviceImportForm(NetBoxModelImportForm):
device_role = CSVModelChoiceField( device_role = CSVModelChoiceField(
label=_('Device role'),
queryset=DeviceRole.objects.all(), queryset=DeviceRole.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Assigned role') help_text=_('Assigned role')
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Assigned tenant') help_text=_('Assigned tenant')
) )
manufacturer = CSVModelChoiceField( manufacturer = CSVModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Device type manufacturer') help_text=_('Device type manufacturer')
) )
device_type = CSVModelChoiceField( device_type = CSVModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all(), queryset=DeviceType.objects.all(),
to_field_name='model', to_field_name='model',
help_text=_('Device type model') help_text=_('Device type model')
) )
platform = CSVModelChoiceField( platform = CSVModelChoiceField(
label=_('Platform'),
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Assigned platform') help_text=_('Assigned platform')
) )
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=DeviceStatusChoices, choices=DeviceStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
virtual_chassis = CSVModelChoiceField( virtual_chassis = CSVModelChoiceField(
label=_('Virtual chassis'),
queryset=VirtualChassis.objects.all(), queryset=VirtualChassis.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('Virtual chassis') help_text=_('Virtual chassis')
) )
cluster = CSVModelChoiceField( cluster = CSVModelChoiceField(
label=_('Cluster'),
queryset=Cluster.objects.all(), queryset=Cluster.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -430,45 +476,53 @@ class BaseDeviceImportForm(NetBoxModelImportForm):
class DeviceImportForm(BaseDeviceImportForm): class DeviceImportForm(BaseDeviceImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Assigned site') help_text=_('Assigned site')
) )
location = CSVModelChoiceField( location = CSVModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_("Assigned location (if any)") help_text=_("Assigned location (if any)")
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_("Assigned rack (if any)") help_text=_("Assigned rack (if any)")
) )
face = CSVChoiceField( face = CSVChoiceField(
label=_('Face'),
choices=DeviceFaceChoices, choices=DeviceFaceChoices,
required=False, required=False,
help_text=_('Mounted rack face') help_text=_('Mounted rack face')
) )
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('Parent device (for child devices)') help_text=_('Parent device (for child devices)')
) )
device_bay = CSVModelChoiceField( device_bay = CSVModelChoiceField(
label=_('Device bay'),
queryset=DeviceBay.objects.all(), queryset=DeviceBay.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('Device bay in which this device is installed (for child devices)') help_text=_('Device bay in which this device is installed (for child devices)')
) )
airflow = CSVChoiceField( airflow = CSVChoiceField(
label=_('Airflow'),
choices=DeviceAirflowChoices, choices=DeviceAirflowChoices,
required=False, required=False,
help_text=_('Airflow direction') help_text=_('Airflow direction')
) )
config_template = CSVModelChoiceField( config_template = CSVModelChoiceField(
label=_('Config template'),
queryset=ConfigTemplate.objects.all(), queryset=ConfigTemplate.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -523,29 +577,35 @@ class DeviceImportForm(BaseDeviceImportForm):
class ModuleImportForm(ModuleCommonForm, NetBoxModelImportForm): class ModuleImportForm(ModuleCommonForm, NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('The device in which this module is installed') help_text=_('The device in which this module is installed')
) )
module_bay = CSVModelChoiceField( module_bay = CSVModelChoiceField(
label=_('Module bay'),
queryset=ModuleBay.objects.all(), queryset=ModuleBay.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('The module bay in which this module is installed') help_text=_('The module bay in which this module is installed')
) )
module_type = CSVModelChoiceField( module_type = CSVModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(), queryset=ModuleType.objects.all(),
to_field_name='model', to_field_name='model',
help_text=_('The type of module') help_text=_('The type of module')
) )
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=ModuleStatusChoices, choices=ModuleStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
replicate_components = forms.BooleanField( replicate_components = forms.BooleanField(
label=_('Replicate components'),
required=False, required=False,
help_text=_('Automatically populate components associated with this module type (enabled by default)') help_text=_('Automatically populate components associated with this module type (enabled by default)')
) )
adopt_components = forms.BooleanField( adopt_components = forms.BooleanField(
label=_('Adopt components'),
required=False, required=False,
help_text=_('Adopt already existing components') help_text=_('Adopt already existing components')
) )
@ -579,15 +639,18 @@ class ModuleImportForm(ModuleCommonForm, NetBoxModelImportForm):
class ConsolePortImportForm(NetBoxModelImportForm): class ConsolePortImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=ConsolePortTypeChoices, choices=ConsolePortTypeChoices,
required=False, required=False,
help_text=_('Port type') help_text=_('Port type')
) )
speed = CSVTypedChoiceField( speed = CSVTypedChoiceField(
label=_('Speed'),
choices=ConsolePortSpeedChoices, choices=ConsolePortSpeedChoices,
coerce=int, coerce=int,
empty_value=None, empty_value=None,
@ -602,15 +665,18 @@ class ConsolePortImportForm(NetBoxModelImportForm):
class ConsoleServerPortImportForm(NetBoxModelImportForm): class ConsoleServerPortImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=ConsolePortTypeChoices, choices=ConsolePortTypeChoices,
required=False, required=False,
help_text=_('Port type') help_text=_('Port type')
) )
speed = CSVTypedChoiceField( speed = CSVTypedChoiceField(
label=_('Speed'),
choices=ConsolePortSpeedChoices, choices=ConsolePortSpeedChoices,
coerce=int, coerce=int,
empty_value=None, empty_value=None,
@ -625,10 +691,12 @@ class ConsoleServerPortImportForm(NetBoxModelImportForm):
class PowerPortImportForm(NetBoxModelImportForm): class PowerPortImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=PowerPortTypeChoices, choices=PowerPortTypeChoices,
required=False, required=False,
help_text=_('Port type') help_text=_('Port type')
@ -643,21 +711,25 @@ class PowerPortImportForm(NetBoxModelImportForm):
class PowerOutletImportForm(NetBoxModelImportForm): class PowerOutletImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=PowerOutletTypeChoices, choices=PowerOutletTypeChoices,
required=False, required=False,
help_text=_('Outlet type') help_text=_('Outlet type')
) )
power_port = CSVModelChoiceField( power_port = CSVModelChoiceField(
label=_('Power port'),
queryset=PowerPort.objects.all(), queryset=PowerPort.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Local power port which feeds this outlet') help_text=_('Local power port which feeds this outlet')
) )
feed_leg = CSVChoiceField( feed_leg = CSVChoiceField(
label=_('Feed lag'),
choices=PowerOutletFeedLegChoices, choices=PowerOutletFeedLegChoices,
required=False, required=False,
help_text=_('Electrical phase (for three-phase circuits)') help_text=_('Electrical phase (for three-phase circuits)')
@ -692,63 +764,75 @@ class PowerOutletImportForm(NetBoxModelImportForm):
class InterfaceImportForm(NetBoxModelImportForm): class InterfaceImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=Interface.objects.all(), queryset=Interface.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Parent interface') help_text=_('Parent interface')
) )
bridge = CSVModelChoiceField( bridge = CSVModelChoiceField(
label=_('Bridge'),
queryset=Interface.objects.all(), queryset=Interface.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Bridged interface') help_text=_('Bridged interface')
) )
lag = CSVModelChoiceField( lag = CSVModelChoiceField(
label=_('Lag'),
queryset=Interface.objects.all(), queryset=Interface.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Parent LAG interface') help_text=_('Parent LAG interface')
) )
vdcs = CSVModelMultipleChoiceField( vdcs = CSVModelMultipleChoiceField(
label=_('Vdcs'),
queryset=VirtualDeviceContext.objects.all(), queryset=VirtualDeviceContext.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='VDC names separated by commas, encased with double quotes (e.g. "vdc1, vdc2, vdc3")' help_text=_('VDC names separated by commas, encased with double quotes (e.g. "vdc1, vdc2, vdc3")')
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=InterfaceTypeChoices, choices=InterfaceTypeChoices,
help_text=_('Physical medium') help_text=_('Physical medium')
) )
duplex = CSVChoiceField( duplex = CSVChoiceField(
label=_('Duplex'),
choices=InterfaceDuplexChoices, choices=InterfaceDuplexChoices,
required=False required=False
) )
poe_mode = CSVChoiceField( poe_mode = CSVChoiceField(
label=_('Poe mode'),
choices=InterfacePoEModeChoices, choices=InterfacePoEModeChoices,
required=False, required=False,
help_text=_('PoE mode') help_text=_('PoE mode')
) )
poe_type = CSVChoiceField( poe_type = CSVChoiceField(
label=_('Poe type'),
choices=InterfacePoETypeChoices, choices=InterfacePoETypeChoices,
required=False, required=False,
help_text=_('PoE type') help_text=_('PoE type')
) )
mode = CSVChoiceField( mode = CSVChoiceField(
label=_('Mode'),
choices=InterfaceModeChoices, choices=InterfaceModeChoices,
required=False, required=False,
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'),
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
required=False, required=False,
to_field_name='rd', to_field_name='rd',
help_text=_('Assigned VRF') help_text=_('Assigned VRF')
) )
rf_role = CSVChoiceField( rf_role = CSVChoiceField(
label=_('Rf role'),
choices=WirelessRoleChoices, choices=WirelessRoleChoices,
required=False, required=False,
help_text=_('Wireless role (AP/station)') help_text=_('Wireless role (AP/station)')
@ -792,15 +876,18 @@ class InterfaceImportForm(NetBoxModelImportForm):
class FrontPortImportForm(NetBoxModelImportForm): class FrontPortImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
rear_port = CSVModelChoiceField( rear_port = CSVModelChoiceField(
label=_('Rear port'),
queryset=RearPort.objects.all(), queryset=RearPort.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Corresponding rear port') help_text=_('Corresponding rear port')
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=PortTypeChoices, choices=PortTypeChoices,
help_text=_('Physical medium classification') help_text=_('Physical medium classification')
) )
@ -837,10 +924,12 @@ class FrontPortImportForm(NetBoxModelImportForm):
class RearPortImportForm(NetBoxModelImportForm): class RearPortImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
help_text=_('Physical medium classification'), help_text=_('Physical medium classification'),
choices=PortTypeChoices, choices=PortTypeChoices,
) )
@ -852,6 +941,7 @@ class RearPortImportForm(NetBoxModelImportForm):
class ModuleBayImportForm(NetBoxModelImportForm): class ModuleBayImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
@ -863,10 +953,12 @@ class ModuleBayImportForm(NetBoxModelImportForm):
class DeviceBayImportForm(NetBoxModelImportForm): class DeviceBayImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
installed_device = CSVModelChoiceField( installed_device = CSVModelChoiceField(
label=_('Installed device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
@ -909,32 +1001,38 @@ class DeviceBayImportForm(NetBoxModelImportForm):
class InventoryItemImportForm(NetBoxModelImportForm): class InventoryItemImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name' to_field_name='name'
) )
role = CSVModelChoiceField( role = CSVModelChoiceField(
label=_('Role'),
queryset=InventoryItemRole.objects.all(), queryset=InventoryItemRole.objects.all(),
to_field_name='name', to_field_name='name',
required=False required=False
) )
manufacturer = CSVModelChoiceField( manufacturer = CSVModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name', to_field_name='name',
required=False required=False
) )
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
label=_('Parent'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('Parent inventory item') help_text=_('Parent inventory item')
) )
component_type = CSVContentTypeField( component_type = CSVContentTypeField(
label=_('Component type'),
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
limit_choices_to=MODULAR_COMPONENT_MODELS, limit_choices_to=MODULAR_COMPONENT_MODELS,
required=False, required=False,
help_text=_('Component Type') help_text=_('Component Type')
) )
component_name = forms.CharField( component_name = forms.CharField(
label=_('Compnent name'),
required=False, required=False,
help_text=_('Component Name') help_text=_('Component Name')
) )
@ -985,7 +1083,9 @@ class InventoryItemImportForm(NetBoxModelImportForm):
# #
class InventoryItemRoleImportForm(NetBoxModelImportForm): class InventoryItemRoleImportForm(NetBoxModelImportForm):
slug = SlugField() slug = SlugField(
label=_('Slug'),
)
class Meta: class Meta:
model = InventoryItemRole model = InventoryItemRole
@ -1002,52 +1102,62 @@ class InventoryItemRoleImportForm(NetBoxModelImportForm):
class CableImportForm(NetBoxModelImportForm): class CableImportForm(NetBoxModelImportForm):
# Termination A # Termination A
side_a_device = CSVModelChoiceField( side_a_device = CSVModelChoiceField(
label=_('Side a device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Side A device') help_text=_('Side A device')
) )
side_a_type = CSVContentTypeField( side_a_type = CSVContentTypeField(
label=_('Side a type'),
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
limit_choices_to=CABLE_TERMINATION_MODELS, limit_choices_to=CABLE_TERMINATION_MODELS,
help_text=_('Side A type') help_text=_('Side A type')
) )
side_a_name = forms.CharField( side_a_name = forms.CharField(
label=_('Side a name'),
help_text=_('Side A component name') help_text=_('Side A component name')
) )
# Termination B # Termination B
side_b_device = CSVModelChoiceField( side_b_device = CSVModelChoiceField(
label=_('Side b device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Side B device') help_text=_('Side B device')
) )
side_b_type = CSVContentTypeField( side_b_type = CSVContentTypeField(
label=_('Side b type'),
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
limit_choices_to=CABLE_TERMINATION_MODELS, limit_choices_to=CABLE_TERMINATION_MODELS,
help_text=_('Side B type') help_text=_('Side B type')
) )
side_b_name = forms.CharField( side_b_name = forms.CharField(
label=_('Side b name'),
help_text=_('Side B component name') help_text=_('Side B component name')
) )
# Cable attributes # Cable attributes
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=LinkStatusChoices, choices=LinkStatusChoices,
required=False, required=False,
help_text=_('Connection status') help_text=_('Connection status')
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=CableTypeChoices, choices=CableTypeChoices,
required=False, required=False,
help_text=_('Physical medium classification') help_text=_('Physical medium classification')
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text=_('Assigned tenant') help_text=_('Assigned tenant')
) )
length_unit = CSVChoiceField( length_unit = CSVChoiceField(
label=_('Length unit'),
choices=CableLengthUnitChoices, choices=CableLengthUnitChoices,
required=False, required=False,
help_text=_('Length unit') help_text=_('Length unit')
@ -1110,6 +1220,7 @@ class CableImportForm(NetBoxModelImportForm):
class VirtualChassisImportForm(NetBoxModelImportForm): class VirtualChassisImportForm(NetBoxModelImportForm):
master = CSVModelChoiceField( master = CSVModelChoiceField(
label=_('Master'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
@ -1127,11 +1238,13 @@ class VirtualChassisImportForm(NetBoxModelImportForm):
class PowerPanelImportForm(NetBoxModelImportForm): class PowerPanelImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Name of parent site') help_text=_('Name of parent site')
) )
location = CSVModelChoiceField( location = CSVModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
required=False, required=False,
to_field_name='name' to_field_name='name'
@ -1153,40 +1266,48 @@ class PowerPanelImportForm(NetBoxModelImportForm):
class PowerFeedImportForm(NetBoxModelImportForm): class PowerFeedImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Assigned site') help_text=_('Assigned site')
) )
power_panel = CSVModelChoiceField( power_panel = CSVModelChoiceField(
label=_('Power panel'),
queryset=PowerPanel.objects.all(), queryset=PowerPanel.objects.all(),
to_field_name='name', to_field_name='name',
help_text=_('Upstream power panel') help_text=_('Upstream power panel')
) )
location = CSVModelChoiceField( location = CSVModelChoiceField(
label=_('Location'),
queryset=Location.objects.all(), queryset=Location.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_("Rack's location (if any)") help_text=_("Rack's location (if any)")
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
label=_('Rack'),
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text=_('Rack') help_text=_('Rack')
) )
status = CSVChoiceField( status = CSVChoiceField(
label=_('Status'),
choices=PowerFeedStatusChoices, choices=PowerFeedStatusChoices,
help_text=_('Operational status') help_text=_('Operational status')
) )
type = CSVChoiceField( type = CSVChoiceField(
label=_('Type'),
choices=PowerFeedTypeChoices, choices=PowerFeedTypeChoices,
help_text=_('Primary or redundant') help_text=_('Primary or redundant')
) )
supply = CSVChoiceField( supply = CSVChoiceField(
label=_('Supply'),
choices=PowerFeedSupplyChoices, choices=PowerFeedSupplyChoices,
help_text=_('Supply type (AC/DC)') help_text=_('Supply type (AC/DC)')
) )
phase = CSVChoiceField( phase = CSVChoiceField(
label=_('Phase'),
choices=PowerFeedPhaseChoices, choices=PowerFeedPhaseChoices,
help_text=_('Single or three-phase') help_text=_('Single or three-phase')
) )
@ -1222,11 +1343,13 @@ class PowerFeedImportForm(NetBoxModelImportForm):
class VirtualDeviceContextImportForm(NetBoxModelImportForm): class VirtualDeviceContextImportForm(NetBoxModelImportForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned role' help_text='Assigned role'
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',

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 dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
@ -47,7 +47,7 @@ class InterfaceCommonForm(forms.Form):
# Untagged interfaces cannot be assigned tagged VLANs # Untagged interfaces cannot be assigned tagged VLANs
if self.cleaned_data['mode'] == InterfaceModeChoices.MODE_ACCESS and tagged_vlans: if self.cleaned_data['mode'] == InterfaceModeChoices.MODE_ACCESS and tagged_vlans:
raise forms.ValidationError({ raise forms.ValidationError({
'mode': "An access interface cannot have tagged VLANs assigned." 'mode': _("An access interface cannot have tagged VLANs assigned.")
}) })
# Remove all tagged VLAN assignments from "tagged all" interfaces # Remove all tagged VLAN assignments from "tagged all" interfaces
@ -61,8 +61,8 @@ class InterfaceCommonForm(forms.Form):
if invalid_vlans: if invalid_vlans:
raise forms.ValidationError({ raise forms.ValidationError({
'tagged_vlans': f"The tagged VLANs ({', '.join(invalid_vlans)}) must belong to the same site as " 'tagged_vlans': _("The tagged VLANs ({vlans}) must belong to the same site as "
f"the interface's parent device/VM, or they must be global" "the interface's parent device/VM, or they must be global").format(vlans=', '.join(invalid_vlans))
}) })
@ -105,7 +105,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 +114,12 @@ 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(
f"Cannot adopt {template.component_model.__name__} '{resolved_name}' as it already belongs " _("Cannot adopt {name} '{resolved_name}' as it already belongs "
f"to a module" "to a module").format(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(
f"{template.component_model.__name__} - {resolved_name} already exists" _("{name} - {resolved_name} already exists").format(name=template.component_model.__name__, resolved_name=resolved_name)
) )