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

Standardized naming of reverse relationships from component templates to DeviceType

Jeremy Stretch 7 лет назад
Родитель
Сommit
3ea2978df4

+ 6 - 6
netbox/dcim/filters.py

@@ -355,19 +355,19 @@ class DeviceTypeFilter(CustomFieldFilterSet, django_filters.FilterSet):
 
     def _console_ports(self, queryset, name, value):
         value = value.strip()
-        return queryset.exclude(console_port_templates__isnull=bool(value))
+        return queryset.exclude(consoleport_templates__isnull=bool(value))
 
     def _console_server_ports(self, queryset, name, value):
         value = value.strip()
-        return queryset.exclude(cs_port_templates__isnull=bool(value))
+        return queryset.exclude(consoleserverport_templates__isnull=bool(value))
 
     def _power_ports(self, queryset, name, value):
         value = value.strip()
-        return queryset.exclude(power_port_templates__isnull=bool(value))
+        return queryset.exclude(powerport_templates__isnull=bool(value))
 
     def _power_outlets(self, queryset, name, value):
         value = value.strip()
-        return queryset.exclude(power_outlet_templates__isnull=bool(value))
+        return queryset.exclude(poweroutlet_templates__isnull=bool(value))
 
     def _interfaces(self, queryset, name, value):
         value = value.strip()
@@ -376,8 +376,8 @@ class DeviceTypeFilter(CustomFieldFilterSet, django_filters.FilterSet):
     def _pass_through_ports(self, queryset, name, value):
         value = value.strip()
         return queryset.exclude(
-            front_port_templates__isnull=bool(value),
-            rear_port_templates__isnull=bool(value)
+            frontport_templates__isnull=bool(value),
+            rearport_templates__isnull=bool(value)
         )
 
 

+ 1 - 1
netbox/dcim/forms.py

@@ -807,7 +807,7 @@ class FrontPortTemplateCreateForm(ComponentForm):
         # Determine which rear port positions are occupied. These will be excluded from the list of available mappings.
         occupied_port_positions = [
             (front_port.rear_port_id, front_port.rear_port_position)
-            for front_port in self.parent.front_port_templates.all()
+            for front_port in self.parent.frontport_templates.all()
         ]
 
         # Populate rear port choices

+ 26 - 6
netbox/dcim/migrations/0065_front_rear_ports.py

@@ -1,5 +1,3 @@
-# Generated by Django 2.0.8 on 2018-10-03 17:26
-
 import django.core.validators
 from django.db import migrations, models
 import django.db.models.deletion
@@ -68,22 +66,22 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='rearporttemplate',
             name='device_type',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rear_port_templates', to='dcim.DeviceType'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rearport_templates', to='dcim.DeviceType'),
         ),
         migrations.AddField(
             model_name='frontporttemplate',
             name='device_type',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_port_templates', to='dcim.DeviceType'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontport_templates', to='dcim.DeviceType'),
         ),
         migrations.AddField(
             model_name='frontporttemplate',
             name='rear_port',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_port_templates', to='dcim.RearPortTemplate'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontport_templates', to='dcim.RearPortTemplate'),
         ),
         migrations.AddField(
             model_name='frontport',
             name='rear_port',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='front_ports', to='dcim.RearPort'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frontports', to='dcim.RearPort'),
         ),
         migrations.AddField(
             model_name='frontport',
@@ -106,4 +104,26 @@ class Migration(migrations.Migration):
             name='frontport',
             unique_together={('device', 'name'), ('rear_port', 'rear_port_position')},
         ),
+
+        # Rename reverse relationships of component templates to DeviceType
+        migrations.AlterField(
+            model_name='consoleporttemplate',
+            name='device_type',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consoleport_templates', to='dcim.DeviceType'),
+        ),
+        migrations.AlterField(
+            model_name='consoleserverporttemplate',
+            name='device_type',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consoleserverport_templates', to='dcim.DeviceType'),
+        ),
+        migrations.AlterField(
+            model_name='poweroutlettemplate',
+            name='device_type',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='poweroutlet_templates', to='dcim.DeviceType'),
+        ),
+        migrations.AlterField(
+            model_name='powerporttemplate',
+            name='device_type',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='powerport_templates', to='dcim.DeviceType'),
+        ),
     ]

+ 15 - 15
netbox/dcim/models.py

@@ -965,7 +965,7 @@ class ConsolePortTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='console_port_templates'
+        related_name='consoleport_templates'
     )
     name = models.CharField(
         max_length=50
@@ -986,7 +986,7 @@ class ConsoleServerPortTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='cs_port_templates'
+        related_name='consoleserverport_templates'
     )
     name = models.CharField(
         max_length=50
@@ -1007,7 +1007,7 @@ class PowerPortTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='power_port_templates'
+        related_name='powerport_templates'
     )
     name = models.CharField(
         max_length=50
@@ -1028,7 +1028,7 @@ class PowerOutletTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='power_outlet_templates'
+        related_name='poweroutlet_templates'
     )
     name = models.CharField(
         max_length=50
@@ -1080,7 +1080,7 @@ class FrontPortTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='front_port_templates'
+        related_name='frontport_templates'
     )
     name = models.CharField(
         max_length=64
@@ -1091,7 +1091,7 @@ class FrontPortTemplate(ComponentTemplateModel):
     rear_port = models.ForeignKey(
         to='dcim.RearPortTemplate',
         on_delete=models.CASCADE,
-        related_name='front_port_templates'
+        related_name='frontport_templates'
     )
     rear_port_position = models.PositiveSmallIntegerField(
         default=1,
@@ -1132,7 +1132,7 @@ class RearPortTemplate(ComponentTemplateModel):
     device_type = models.ForeignKey(
         to='dcim.DeviceType',
         on_delete=models.CASCADE,
-        related_name='rear_port_templates'
+        related_name='rearport_templates'
     )
     name = models.CharField(
         max_length=64
@@ -1552,19 +1552,19 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
         if is_new:
             ConsolePort.objects.bulk_create(
                 [ConsolePort(device=self, name=template.name) for template in
-                 self.device_type.console_port_templates.all()]
+                 self.device_type.consoleport_templates.all()]
             )
             ConsoleServerPort.objects.bulk_create(
                 [ConsoleServerPort(device=self, name=template.name) for template in
-                 self.device_type.cs_port_templates.all()]
+                 self.device_type.consoleserverport_templates.all()]
             )
             PowerPort.objects.bulk_create(
                 [PowerPort(device=self, name=template.name) for template in
-                 self.device_type.power_port_templates.all()]
+                 self.device_type.powerport_templates.all()]
             )
             PowerOutlet.objects.bulk_create(
                 [PowerOutlet(device=self, name=template.name) for template in
-                 self.device_type.power_outlet_templates.all()]
+                 self.device_type.poweroutlet_templates.all()]
             )
             Interface.objects.bulk_create(
                 [Interface(device=self, name=template.name, form_factor=template.form_factor,
@@ -1576,7 +1576,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
                     name=template.name,
                     type=template.type,
                     positions=template.positions
-                ) for template in self.device_type.rear_port_templates.all()
+                ) for template in self.device_type.rearport_templates.all()
             ])
             FrontPort.objects.bulk_create([
                 FrontPort(
@@ -1585,7 +1585,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
                     type=template.type,
                     rear_port=RearPort.objects.get(device=self, name=template.rear_port.name),
                     rear_port_position=template.rear_port_position,
-                ) for template in self.device_type.front_port_templates.all()
+                ) for template in self.device_type.frontport_templates.all()
             ])
             DeviceBay.objects.bulk_create(
                 [DeviceBay(device=self, name=template.name) for template in
@@ -2120,7 +2120,7 @@ class FrontPort(CableTermination, ComponentModel):
     rear_port = models.ForeignKey(
         to='dcim.RearPort',
         on_delete=models.CASCADE,
-        related_name='front_ports'
+        related_name='frontports'
     )
     rear_port_position = models.PositiveSmallIntegerField(
         default=1,
@@ -2546,7 +2546,7 @@ class Cable(ChangeLoggedModel):
             if next_cable is None:
                 return None
 
-            far_end = next_cable.termination_b if next_cable.termination_a == peer_port else next_cable.terimation_a
+            far_end = next_cable.termination_b if next_cable.termination_a == peer_port else next_cable.termination_a
 
             # Return the far side termination of the cable
             return trace_cable(far_end, position)

+ 7 - 7
netbox/templates/dcim/devicetype.html

@@ -136,7 +136,7 @@
         </div>
     </div>
 </div>
-{% if devicetype.console_port_templates.exists or devicetype.power_port_templates.exists %}
+{% if devicetype.consoleport_templates.exists or devicetype.powerport_templates.exists %}
     <div class="row">
         <div class="col-md-6">
             {% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' add_url='dcim:devicetype_add_consoleport' delete_url='dcim:devicetype_delete_consoleport' %}
@@ -153,28 +153,28 @@
         </div>
     </div>
 {% endif %}
-{% if devicetype.cs_port_templates.exists %}
+{% if devicetype.consoleserverport_templates.exists %}
     <div class="row">
         <div class="col-md-12">
             {% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' add_url='dcim:devicetype_add_consoleserverport' delete_url='dcim:devicetype_delete_consoleserverport' %}
         </div>
     </div>
 {% endif %}
-{% if devicetype.interface_templates.exists %}
+{% if devicetype.poweroutlet_templates.exists %}
     <div class="row">
         <div class="col-md-12">
-            {% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfacaes' add_url='dcim:devicetype_add_interface' delete_url='dcim:devicetype_delete_interface' %}
+            {% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
         </div>
     </div>
 {% endif %}
-{% if devicetype.power_outlet_templates.exists %}
+{% if devicetype.interface_templates.exists %}
     <div class="row">
         <div class="col-md-12">
-            {% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
+            {% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfacaes' add_url='dcim:devicetype_add_interface' delete_url='dcim:devicetype_delete_interface' %}
         </div>
     </div>
 {% endif %}
-{% if devicetype.front_port_templates.exists or devicetype.rear_port_templates.exists %}
+{% if devicetype.frontport_templates.exists or devicetype.rearport_templates.exists %}
     <div class="row">
         <div class="col-md-6">
             {% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' add_url='dcim:devicetype_add_frontport' delete_url='dcim:devicetype_delete_frontport' %}