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

Fixes: #14839 - Check for tunnel termination type in data and instance in addition to intially passed data. (#14995)

* Fixes: #14839 - Check for tunnel termination type in additional instances

* Incorporate recommended changes
This commit is contained in:
Daniel Sheppard
2024-02-05 08:59:24 -06:00
committed by GitHub
parent 31fb6961e9
commit 1a9149d7d4

View File

@ -265,9 +265,15 @@ class TunnelTerminationForm(NetBoxModelForm):
def __init__(self, *args, initial=None, **kwargs): def __init__(self, *args, initial=None, **kwargs):
super().__init__(*args, initial=initial, **kwargs) super().__init__(*args, initial=initial, **kwargs)
if initial and initial.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE: if (get_field_value(self, 'type') is None and
self.instance.pk and isinstance(self.instance.termination.parent_object, VirtualMachine)):
self.fields['type'].initial = TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE
# If initial or self.data is set and the type is a VIRTUALMACHINE type, swap the field querysets.
if get_field_value(self, 'type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE:
self.fields['parent'].label = _('Virtual Machine') self.fields['parent'].label = _('Virtual Machine')
self.fields['parent'].queryset = VirtualMachine.objects.all() self.fields['parent'].queryset = VirtualMachine.objects.all()
self.fields['parent'].widget.attrs['selector'] = 'virtualization.virtualmachine'
self.fields['termination'].queryset = VMInterface.objects.all() self.fields['termination'].queryset = VMInterface.objects.all()
self.fields['termination'].widget.add_query_params({ self.fields['termination'].widget.add_query_params({
'virtual_machine_id': '$parent', 'virtual_machine_id': '$parent',