1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #4775: Allow selecting an alternate device type when creating component templates

This commit is contained in:
Jeremy Stretch
2020-06-18 11:59:24 -04:00
parent 0800279325
commit c5dc075fb0
3 changed files with 38 additions and 56 deletions

View File

@ -6,6 +6,7 @@
* [#4766](https://github.com/netbox-community/netbox/issues/4766) - Fix redirect after login when `next` is not specified * [#4766](https://github.com/netbox-community/netbox/issues/4766) - Fix redirect after login when `next` is not specified
* [#4772](https://github.com/netbox-community/netbox/issues/4772) - Fix "brief" format for the secrets REST API endpoint * [#4772](https://github.com/netbox-community/netbox/issues/4772) - Fix "brief" format for the secrets REST API endpoint
* [#4775](https://github.com/netbox-community/netbox/issues/4775) - Allow selecting an alternate device type when creating component templates
--- ---

View File

@ -1026,6 +1026,30 @@ class DeviceTypeFilterForm(BootstrapMixin, CustomFieldFilterForm):
# Device component templates # Device component templates
# #
class ComponentTemplateCreateForm(BootstrapMixin, forms.Form):
"""
Base form for the creation of device component templates.
"""
manufacturer = DynamicModelChoiceField(
queryset=Manufacturer.objects.all(),
required=False,
widget=APISelect(
filter_for={
'device_type': 'manufacturer_id'
}
)
)
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all(),
widget=APISelect(
display_field='model'
)
)
name_pattern = ExpandableNameField(
label='Name'
)
class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm): class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
@ -1038,13 +1062,7 @@ class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class ConsolePortTemplateCreateForm(BootstrapMixin, forms.Form): class ConsolePortTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=add_blank_choice(ConsolePortTypeChoices), choices=add_blank_choice(ConsolePortTypeChoices),
widget=StaticSelect2() widget=StaticSelect2()
@ -1078,13 +1096,7 @@ class ConsoleServerPortTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class ConsoleServerPortTemplateCreateForm(BootstrapMixin, forms.Form): class ConsoleServerPortTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=add_blank_choice(ConsolePortTypeChoices), choices=add_blank_choice(ConsolePortTypeChoices),
widget=StaticSelect2() widget=StaticSelect2()
@ -1118,13 +1130,7 @@ class PowerPortTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class PowerPortTemplateCreateForm(BootstrapMixin, forms.Form): class PowerPortTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=add_blank_choice(PowerPortTypeChoices), choices=add_blank_choice(PowerPortTypeChoices),
required=False required=False
@ -1188,13 +1194,7 @@ class PowerOutletTemplateForm(BootstrapMixin, forms.ModelForm):
) )
class PowerOutletTemplateCreateForm(BootstrapMixin, forms.Form): class PowerOutletTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=add_blank_choice(PowerOutletTypeChoices), choices=add_blank_choice(PowerOutletTypeChoices),
required=False required=False
@ -1275,13 +1275,7 @@ class InterfaceTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class InterfaceTemplateCreateForm(BootstrapMixin, forms.Form): class InterfaceTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=InterfaceTypeChoices, choices=InterfaceTypeChoices,
widget=StaticSelect2() widget=StaticSelect2()
@ -1335,13 +1329,7 @@ class FrontPortTemplateForm(BootstrapMixin, forms.ModelForm):
) )
class FrontPortTemplateCreateForm(BootstrapMixin, forms.Form): class FrontPortTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=PortTypeChoices, choices=PortTypeChoices,
widget=StaticSelect2() widget=StaticSelect2()
@ -1426,13 +1414,7 @@ class RearPortTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class RearPortTemplateCreateForm(BootstrapMixin, forms.Form): class RearPortTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField(
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
type = forms.ChoiceField( type = forms.ChoiceField(
choices=PortTypeChoices, choices=PortTypeChoices,
widget=StaticSelect2(), widget=StaticSelect2(),
@ -1472,13 +1454,8 @@ class DeviceBayTemplateForm(BootstrapMixin, forms.ModelForm):
} }
class DeviceBayTemplateCreateForm(BootstrapMixin, forms.Form): class DeviceBayTemplateCreateForm(ComponentTemplateCreateForm):
device_type = DynamicModelChoiceField( pass
queryset=DeviceType.objects.all()
)
name_pattern = ExpandableNameField(
label='Name'
)
# TODO: DeviceBayTemplate has no fields suitable for bulk-editing yet # TODO: DeviceBayTemplate has no fields suitable for bulk-editing yet

View File

@ -950,6 +950,10 @@ class ComponentCreateView(GetReturnURLMixin, View):
)) ))
if '_addanother' in request.POST: if '_addanother' in request.POST:
return redirect(request.get_full_path()) return redirect(request.get_full_path())
elif 'device_type' in form.cleaned_data:
return redirect(form.cleaned_data['device_type'].get_absolute_url())
elif 'device' in form.cleaned_data:
return redirect(form.cleaned_data['device'].get_absolute_url())
else: else:
return redirect(self.get_return_url(request)) return redirect(self.get_return_url(request))