Просмотр исходного кода

Introduce MODULE_TOKEN constant

jeremystretch 3 лет назад
Родитель
Сommit
1726593fb0

+ 2 - 0
netbox/dcim/constants.py

@@ -62,6 +62,8 @@ POWERFEED_MAX_UTILIZATION_DEFAULT = 80  # Percentage
 # Device components
 #
 
+MODULE_TOKEN = '{module}'
+
 MODULAR_COMPONENT_TEMPLATE_MODELS = Q(
     app_label='dcim',
     model__in=(

+ 4 - 3
netbox/dcim/forms/models.py

@@ -705,18 +705,19 @@ class ModuleForm(NetBoxModelForm):
             # Get the templates for the module type.
             for template in getattr(module_type, templates).all():
                 # 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(
                         "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)
 
                 # It is not possible to adopt components already belonging to a module
                 if adopt_components and existing_item and existing_item.module:
                     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

+ 2 - 2
netbox/dcim/models/device_component_templates.py

@@ -121,12 +121,12 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
 
     def resolve_name(self, 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
 
     def resolve_label(self, 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