mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 19:18:16 -06:00
15541 update InventoryItemTemplateForm
This commit is contained in:
parent
c32dff5649
commit
b6f8532eb6
@ -1002,6 +1002,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
queryset=Manufacturer.objects.all(),
|
queryset=Manufacturer.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assigned component selectors
|
# Assigned component selectors
|
||||||
consoleporttemplate = DynamicModelChoiceField(
|
consoleporttemplate = DynamicModelChoiceField(
|
||||||
queryset=ConsolePortTemplate.objects.all(),
|
queryset=ConsolePortTemplate.objects.all(),
|
||||||
@ -1009,7 +1010,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Console port template')
|
label=_('Console port')
|
||||||
)
|
)
|
||||||
consoleserverporttemplate = DynamicModelChoiceField(
|
consoleserverporttemplate = DynamicModelChoiceField(
|
||||||
queryset=ConsoleServerPortTemplate.objects.all(),
|
queryset=ConsoleServerPortTemplate.objects.all(),
|
||||||
@ -1017,7 +1018,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Console server port template')
|
label=_('Console server port')
|
||||||
)
|
)
|
||||||
frontporttemplate = DynamicModelChoiceField(
|
frontporttemplate = DynamicModelChoiceField(
|
||||||
queryset=FrontPortTemplate.objects.all(),
|
queryset=FrontPortTemplate.objects.all(),
|
||||||
@ -1025,7 +1026,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Front port template')
|
label=_('Front port')
|
||||||
)
|
)
|
||||||
interfacetemplate = DynamicModelChoiceField(
|
interfacetemplate = DynamicModelChoiceField(
|
||||||
queryset=InterfaceTemplate.objects.all(),
|
queryset=InterfaceTemplate.objects.all(),
|
||||||
@ -1041,7 +1042,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Power outlet template')
|
label=_('Power outlet')
|
||||||
)
|
)
|
||||||
powerporttemplate = DynamicModelChoiceField(
|
powerporttemplate = DynamicModelChoiceField(
|
||||||
queryset=PowerPortTemplate.objects.all(),
|
queryset=PowerPortTemplate.objects.all(),
|
||||||
@ -1049,7 +1050,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Power port template')
|
label=_('Power port')
|
||||||
)
|
)
|
||||||
rearporttemplate = DynamicModelChoiceField(
|
rearporttemplate = DynamicModelChoiceField(
|
||||||
queryset=RearPortTemplate.objects.all(),
|
queryset=RearPortTemplate.objects.all(),
|
||||||
@ -1057,14 +1058,25 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
query_params={
|
query_params={
|
||||||
'device_type_id': '$device_type'
|
'device_type_id': '$device_type'
|
||||||
},
|
},
|
||||||
label=_('Rear port template')
|
label=_('Rear port')
|
||||||
)
|
)
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'device_type', 'parent', 'name', 'label', 'role', 'manufacturer', 'part_id', 'description',
|
'device_type', 'parent', 'name', 'label', 'role', 'manufacturer', 'part_id', 'description',
|
||||||
'component_type', 'component_id',
|
|
||||||
),
|
),
|
||||||
|
FieldSet(
|
||||||
|
TabbedGroups(
|
||||||
|
FieldSet('interfacetemplate', name=_('Interface')),
|
||||||
|
FieldSet('consoleporttemplate', name=_('Console Port')),
|
||||||
|
FieldSet('consoleserverporttemplate', name=_('Console Server Port')),
|
||||||
|
FieldSet('frontporttemplate', name=_('Front Port')),
|
||||||
|
FieldSet('rearporttemplate', name=_('Rear Port')),
|
||||||
|
FieldSet('powerporttemplate', name=_('Power Port')),
|
||||||
|
FieldSet('poweroutlettemplate', name=_('Power Outlet')),
|
||||||
|
),
|
||||||
|
name=_('Component Assignment')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -1079,22 +1091,17 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
|
|||||||
component_type = initial.get('component_type')
|
component_type = initial.get('component_type')
|
||||||
component_id = initial.get('component_id')
|
component_id = initial.get('component_id')
|
||||||
|
|
||||||
# Used for picking the default active tab for component selection
|
|
||||||
self.no_component = True
|
|
||||||
|
|
||||||
if instance:
|
if instance:
|
||||||
# When editing set the initial value for component selection
|
# When editing set the initial value for component selection
|
||||||
for component_model in ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS):
|
for component_model in ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS):
|
||||||
if type(instance.component) is component_model.model_class():
|
if type(instance.component) is component_model.model_class():
|
||||||
initial[component_model.model] = instance.component
|
initial[component_model.model] = instance.component
|
||||||
self.no_component = False
|
|
||||||
break
|
break
|
||||||
elif component_type and component_id:
|
elif component_type and component_id:
|
||||||
# When adding the InventoryItem from a component page
|
# When adding the InventoryItem from a component page
|
||||||
if content_type := ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS).filter(pk=component_type).first():
|
if content_type := ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS).filter(pk=component_type).first():
|
||||||
if component := content_type.model_class().objects.filter(pk=component_id).first():
|
if component := content_type.model_class().objects.filter(pk=component_id).first():
|
||||||
initial[content_type.model] = component
|
initial[content_type.model] = component
|
||||||
self.no_component = False
|
|
||||||
|
|
||||||
kwargs['initial'] = initial
|
kwargs['initial'] = initial
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user