mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Overhaul device component template creation views/URLs
This commit is contained in:
@@ -1043,11 +1043,17 @@ class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsolePortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
type = forms.ChoiceField(
|
||||
choices=ConsolePortTypeChoices,
|
||||
choices=add_blank_choice(ConsolePortTypeChoices),
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
|
||||
@@ -1065,6 +1071,12 @@ class ConsoleServerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsoleServerPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1087,6 +1099,12 @@ class PowerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1129,6 +1147,12 @@ class PowerOutletTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerOutletTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1147,12 +1171,11 @@ class PowerOutletTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Limit power_port choices to current DeviceType
|
||||
self.fields['power_port'].queryset = PowerPortTemplate.objects.filter(
|
||||
device_type=self.parent
|
||||
device_type=self.initial.get('device_type')
|
||||
)
|
||||
|
||||
|
||||
@@ -1170,6 +1193,12 @@ class InterfaceTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class InterfaceTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1227,6 +1256,12 @@ class FrontPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class FrontPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1241,18 +1276,19 @@ class FrontPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
device_type = DeviceType.objects.filter(pk=self.initial.get('device_type')).first()
|
||||
|
||||
# Determine which rear port positions are occupied. These will be excluded from the list of available mappings.
|
||||
occupied_port_positions = [
|
||||
(front_port.rear_port_id, front_port.rear_port_position)
|
||||
for front_port in self.parent.frontport_templates.all()
|
||||
for front_port in device_type.frontport_templates.all()
|
||||
]
|
||||
|
||||
# Populate rear port choices
|
||||
choices = []
|
||||
rear_ports = RearPortTemplate.objects.filter(device_type=self.parent)
|
||||
rear_ports = RearPortTemplate.objects.filter(device_type=device_type)
|
||||
for rear_port in rear_ports:
|
||||
for i in range(1, rear_port.positions + 1):
|
||||
if (rear_port.pk, i) not in occupied_port_positions:
|
||||
@@ -1297,6 +1333,12 @@ class RearPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class RearPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
@@ -1325,6 +1367,12 @@ class DeviceBayTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class DeviceBayTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
)
|
||||
)
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user