mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 11:52:22 -06:00
Add positions field on FrontPort; remove legacy fields
This commit is contained in:
@@ -338,9 +338,9 @@ class FrontPortSerializer(NetBoxModelSerializer, CabledObjectSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = FrontPort
|
model = FrontPort
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'device', 'module', 'name', 'label', 'type', 'color', 'rear_port',
|
'id', 'url', 'display_url', 'display', 'device', 'module', 'name', 'label', 'type', 'color', 'positions',
|
||||||
'rear_port_position', 'description', 'mark_connected', 'cable', 'cable_end', 'link_peers',
|
'description', 'mark_connected', 'cable', 'cable_end', 'link_peers', 'link_peers_type', 'tags',
|
||||||
'link_peers_type', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
|
'custom_fields', 'created', 'last_updated', '_occupied',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
|
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
|
||||||
|
|
||||||
|
|||||||
@@ -2101,14 +2101,15 @@ class FrontPortFilterSet(ModularDeviceComponentFilterSet, CabledObjectFilterSet)
|
|||||||
choices=PortTypeChoices,
|
choices=PortTypeChoices,
|
||||||
null_value=None
|
null_value=None
|
||||||
)
|
)
|
||||||
rear_port_id = django_filters.ModelMultipleChoiceFilter(
|
# TODO
|
||||||
queryset=RearPort.objects.all()
|
# rear_port_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
)
|
# queryset=RearPort.objects.all()
|
||||||
|
# )
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FrontPort
|
model = FrontPort
|
||||||
fields = (
|
fields = (
|
||||||
'id', 'name', 'label', 'type', 'color', 'rear_port_position', 'description', 'mark_connected', 'cable_end',
|
'id', 'name', 'label', 'type', 'color', 'positions', 'description', 'mark_connected', 'cable_end',
|
||||||
'cable_position',
|
'cable_position',
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2118,6 +2119,10 @@ class RearPortFilterSet(ModularDeviceComponentFilterSet, CabledObjectFilterSet):
|
|||||||
choices=PortTypeChoices,
|
choices=PortTypeChoices,
|
||||||
null_value=None
|
null_value=None
|
||||||
)
|
)
|
||||||
|
# TODO
|
||||||
|
# front_port_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
# queryset=FrontPort.objects.all()
|
||||||
|
# )
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RearPort
|
model = RearPort
|
||||||
|
|||||||
@@ -1090,8 +1090,7 @@ class FrontPortImportForm(OwnerCSVMixin, NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = FrontPort
|
model = FrontPort
|
||||||
fields = (
|
fields = (
|
||||||
'device', 'name', 'label', 'type', 'color', 'mark_connected', 'rear_port', 'rear_port_position',
|
'device', 'name', 'label', 'type', 'color', 'mark_connected', 'positions', 'description', 'owner', 'tags'
|
||||||
'description', 'owner', 'tags'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -1595,8 +1595,8 @@ class FrontPortForm(ModularDeviceComponentForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = FrontPort
|
model = FrontPort
|
||||||
fields = [
|
fields = [
|
||||||
'device', 'module', 'name', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'mark_connected',
|
'device', 'module', 'name', 'label', 'type', 'color', 'positions', 'mark_connected', 'description', 'owner',
|
||||||
'description', 'owner', 'tags',
|
'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class Meta(model_forms.FrontPortForm.Meta):
|
class Meta(model_forms.FrontPortForm.Meta):
|
||||||
exclude = ('name', 'label', 'rear_port', 'rear_port_position')
|
exclude = ('name', 'label', 'positions')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|||||||
@@ -395,11 +395,7 @@ class DeviceTypeFilter(ImageAttachmentFilterMixin, PrimaryModelFilterMixin, Weig
|
|||||||
class FrontPortFilter(ModularComponentModelFilterMixin, CabledObjectModelFilterMixin):
|
class FrontPortFilter(ModularComponentModelFilterMixin, CabledObjectModelFilterMixin):
|
||||||
type: Annotated['PortTypeEnum', strawberry.lazy('dcim.graphql.enums')] | None = strawberry_django.filter_field()
|
type: Annotated['PortTypeEnum', strawberry.lazy('dcim.graphql.enums')] | None = strawberry_django.filter_field()
|
||||||
color: Annotated['ColorEnum', strawberry.lazy('netbox.graphql.enums')] | None = strawberry_django.filter_field()
|
color: Annotated['ColorEnum', strawberry.lazy('netbox.graphql.enums')] | None = strawberry_django.filter_field()
|
||||||
rear_port: Annotated['RearPortFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
|
rear_ports: Annotated['RearPortFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
|
||||||
strawberry_django.filter_field()
|
|
||||||
)
|
|
||||||
rear_port_id: ID | None = strawberry_django.filter_field()
|
|
||||||
rear_port_position: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
31
netbox/dcim/migrations/0222_frontport_positions.py
Normal file
31
netbox/dcim/migrations/0222_frontport_positions.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '0221_m2m_port_assignments'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='frontport',
|
||||||
|
name='rear_port',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='frontport',
|
||||||
|
name='rear_port_position',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='frontport',
|
||||||
|
name='positions',
|
||||||
|
field=models.PositiveSmallIntegerField(
|
||||||
|
default=1,
|
||||||
|
validators=[
|
||||||
|
django.core.validators.MinValueValidator(1),
|
||||||
|
django.core.validators.MaxValueValidator(1024)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1120,26 +1120,18 @@ class FrontPort(ModularComponentModel, CabledObjectModel, TrackingModelMixin):
|
|||||||
verbose_name=_('color'),
|
verbose_name=_('color'),
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
rear_ports = models.ManyToManyField(
|
positions = models.PositiveSmallIntegerField(
|
||||||
to='dcim.RearPort',
|
verbose_name=_('positions'),
|
||||||
through='dcim.PortAssignment',
|
|
||||||
related_name='front_ports',
|
|
||||||
)
|
|
||||||
|
|
||||||
# Legacy fields
|
|
||||||
rear_port = models.ForeignKey(
|
|
||||||
to='dcim.RearPort',
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name='frontports'
|
|
||||||
)
|
|
||||||
rear_port_position = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('rear port position'),
|
|
||||||
default=1,
|
default=1,
|
||||||
validators=[
|
validators=[
|
||||||
MinValueValidator(PORT_POSITION_MIN),
|
MinValueValidator(PORT_POSITION_MIN),
|
||||||
MaxValueValidator(PORT_POSITION_MAX)
|
MaxValueValidator(PORT_POSITION_MAX)
|
||||||
],
|
],
|
||||||
help_text=_('Mapped position on corresponding rear port')
|
)
|
||||||
|
rear_ports = models.ManyToManyField(
|
||||||
|
to='dcim.RearPort',
|
||||||
|
through='dcim.PortAssignment',
|
||||||
|
related_name='front_ports',
|
||||||
)
|
)
|
||||||
|
|
||||||
clone_fields = ('device', 'type', 'color')
|
clone_fields = ('device', 'type', 'color')
|
||||||
@@ -1205,7 +1197,6 @@ class RearPort(ModularComponentModel, CabledObjectModel, TrackingModelMixin):
|
|||||||
MinValueValidator(PORT_POSITION_MIN),
|
MinValueValidator(PORT_POSITION_MIN),
|
||||||
MaxValueValidator(PORT_POSITION_MAX)
|
MaxValueValidator(PORT_POSITION_MAX)
|
||||||
],
|
],
|
||||||
help_text=_('Number of front ports which may be mapped')
|
|
||||||
)
|
)
|
||||||
clone_fields = ('device', 'type', 'color', 'positions')
|
clone_fields = ('device', 'type', 'color', 'positions')
|
||||||
|
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ def extend_rearport_cable_paths(instance, created, raw, **kwargs):
|
|||||||
When a new FrontPort is created, add it to any CablePaths which end at its corresponding RearPort.
|
When a new FrontPort is created, add it to any CablePaths which end at its corresponding RearPort.
|
||||||
"""
|
"""
|
||||||
if created and not raw:
|
if created and not raw:
|
||||||
rearport = instance.rear_port
|
for rear_port in instance.rear_ports.all():
|
||||||
for cablepath in CablePath.objects.filter(_nodes__contains=rearport):
|
for cablepath in CablePath.objects.filter(_nodes__contains=rear_port):
|
||||||
cablepath.retrace()
|
cablepath.retrace()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -763,12 +763,12 @@ class FrontPortTable(ModularDeviceComponentTable, CableTerminationTable):
|
|||||||
class Meta(DeviceComponentTable.Meta):
|
class Meta(DeviceComponentTable.Meta):
|
||||||
model = models.FrontPort
|
model = models.FrontPort
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'type', 'color', 'rear_port',
|
'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'type', 'color', 'positions', 'description',
|
||||||
'rear_port_position', 'description', 'mark_connected', 'cable', 'cable_color', 'link_peer',
|
'mark_connected', 'cable', 'cable_color', 'link_peer',
|
||||||
'inventory_items', 'tags', 'created', 'last_updated',
|
'inventory_items', 'tags', 'created', 'last_updated',
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'name', 'device', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description',
|
'pk', 'name', 'device', 'label', 'type', 'color', 'positions', 'description',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,8 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Rear Port" %}</th>
|
<th scope="row">{% trans "Positions" %}</th>
|
||||||
<td>{{ object.rear_port|linkify }}</td>
|
<td>{{ object.positions }}</td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">{% trans "Rear Port Position" %}</th>
|
|
||||||
<td>{{ object.rear_port_position }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Description" %}</th>
|
<th scope="row">{% trans "Description" %}</th>
|
||||||
|
|||||||
Reference in New Issue
Block a user