mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce MODULE_TOKEN constant
This commit is contained in:
@ -62,6 +62,8 @@ POWERFEED_MAX_UTILIZATION_DEFAULT = 80 # Percentage
|
|||||||
# Device components
|
# Device components
|
||||||
#
|
#
|
||||||
|
|
||||||
|
MODULE_TOKEN = '{module}'
|
||||||
|
|
||||||
MODULAR_COMPONENT_TEMPLATE_MODELS = Q(
|
MODULAR_COMPONENT_TEMPLATE_MODELS = Q(
|
||||||
app_label='dcim',
|
app_label='dcim',
|
||||||
model__in=(
|
model__in=(
|
||||||
|
@ -705,18 +705,19 @@ class ModuleForm(NetBoxModelForm):
|
|||||||
# Get the templates for the module type.
|
# Get the templates for the module type.
|
||||||
for template in getattr(module_type, templates).all():
|
for template in getattr(module_type, templates).all():
|
||||||
# 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}' 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}', module_bay.position)
|
resolved_name = template.name.replace(MODULE_TOKEN, module_bay.position)
|
||||||
existing_item = installed_components.get(resolved_name)
|
existing_item = installed_components.get(resolved_name)
|
||||||
|
|
||||||
# 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 to a module"
|
f"Cannot adopt {template.component_model.__name__} '{resolved_name}' as it already belongs "
|
||||||
|
f"to a module"
|
||||||
)
|
)
|
||||||
|
|
||||||
# If we are not adopting components we error if the component exists
|
# If we are not adopting components we error if the component exists
|
||||||
|
@ -121,12 +121,12 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
|
|
||||||
def resolve_name(self, module):
|
def resolve_name(self, module):
|
||||||
if module:
|
if module:
|
||||||
return self.name.replace('{module}', module.module_bay.position)
|
return self.name.replace(MODULE_TOKEN, module.module_bay.position)
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def resolve_label(self, module):
|
def resolve_label(self, module):
|
||||||
if module:
|
if module:
|
||||||
return self.label.replace('{module}', module.module_bay.position)
|
return self.label.replace(MODULE_TOKEN, module.module_bay.position)
|
||||||
return self.label
|
return self.label
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user