Fix rear-face image-only labels, click-to-add units, cable concept devices

- Fix "images only" leaving plain labels visible on faces where a
  device has no image for that side (e.g. no rear_image set): the
  view selector now hides every plain label outright in that mode,
  not just the ones an image happens to sit on top of.
- Remove the "Add planned device" button from the elevation card.
  Empty units are now click targets themselves - clicking one opens
  the add-device form pre-filled with that position and face, exactly
  like a real rack's elevation. Occupancy is computed per unit per
  face from the existing device blocks.
- Add cabling for concept devices: ConceptComponent (interfaces,
  front/rear ports, power ports/outlets, console ports) and
  ConceptCable (a connection between two components, restricted to
  devices in the same concept). components.sync_components()
  populates a device's components from its device type's templates,
  including the front/rear port pass-through mapping copied from
  DeviceType.port_mappings - so a device with front/rear port
  templates (a patch panel being the common case) behaves exactly
  like a real one, without hardcoding anything role-specific.
  Placeholder devices without a device type get components added by
  hand. Full CRUD views, tables, filtersets, API endpoints and a
  "Connect" action wired in from the device detail page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 10:18:50 +02:00
co-authored by Claude Sonnet 5
parent e4817ea83b
commit 63538c2efe
24 changed files with 1293 additions and 33 deletions
+132 -2
View File
@@ -16,11 +16,13 @@ from dcim.models import Rack
from netbox.views import generic
from utilities.views import ObjectPermissionRequiredMixin, ViewTab, register_model_view
from . import deploy, filtersets, forms, tables
from . import components, deploy, filtersets, forms, tables
from .elevation import get_elevations
from .models import ConceptDevice, RackConcept
from .models import ConceptCable, ConceptComponent, ConceptDevice, RackConcept
__all__ = (
'ConceptCableView',
'ConceptComponentView',
'ConceptDeviceView',
'MergeConceptsView',
'MergeRacksToConceptView',
@@ -138,6 +140,50 @@ class ConceptDeviceView(generic.ObjectView):
)
template_name = 'netbox_rack_concept/conceptdevice.html'
def get_extra_context(self, request, instance):
component_table = tables.ConceptComponentTable(
instance.components.select_related('device').order_by('component_type', 'name'),
exclude=('device', 'concept'),
orderable=False,
)
component_table.configure(request)
return {
'component_table': component_table,
}
@register_model_view(ConceptDevice, 'sync_components')
class ConceptDeviceSyncComponentsView(ObjectPermissionRequiredMixin, View):
"""Populate a device's components from its device type's templates."""
queryset = ConceptDevice.objects.all()
def get_required_permission(self):
return 'netbox_rack_concept.add_conceptcomponent'
def get(self, request, pk):
device = get_object_or_404(self.queryset.restrict(request.user, 'view'), pk=pk)
return render(request, 'netbox_rack_concept/conceptdevice_sync_components.html', {
'object': device,
'return_url': device.get_absolute_url(),
})
def post(self, request, pk):
device = get_object_or_404(self.queryset.restrict(request.user, 'view'), pk=pk)
if device.device_type is None:
messages.error(request, _('%(device)s has no device type to sync components from.') % {'device': device})
return redirect(device.get_absolute_url())
created, mapped = components.sync_components(device)
if created:
messages.success(request, _('Created %(count)s component(s).') % {'count': created})
else:
messages.info(request, _('No new components to create; everything is already in sync.'))
if mapped:
messages.success(request, _('Mapped %(count)s front/rear port pair(s).') % {'count': mapped})
return redirect(device.get_absolute_url())
@register_model_view(ConceptDevice, 'add', detail=False)
@register_model_view(ConceptDevice, 'edit')
@@ -506,3 +552,87 @@ class RackConceptReorderView(ObjectPermissionRequiredMixin, View):
return JsonResponse({'error': ' '.join(exc.messages)}, status=400)
return JsonResponse({'status': 'ok', 'updated': len(updated)})
#
# Concept components
#
@register_model_view(ConceptComponent, 'list', path='', detail=False)
class ConceptComponentListView(generic.ObjectListView):
queryset = ConceptComponent.objects.select_related('device', 'device__concept')
table = tables.ConceptComponentTable
filterset = filtersets.ConceptComponentFilterSet
filterset_form = forms.ConceptComponentFilterForm
@register_model_view(ConceptComponent)
class ConceptComponentView(generic.ObjectView):
queryset = ConceptComponent.objects.select_related('device', 'device__concept')
template_name = 'netbox_rack_concept/conceptcomponent.html'
def get_extra_context(self, request, instance):
return {
'paired_components': instance.get_paired_components(),
'cable': instance.cable,
}
@register_model_view(ConceptComponent, 'add', detail=False)
@register_model_view(ConceptComponent, 'edit')
class ConceptComponentEditView(generic.ObjectEditView):
queryset = ConceptComponent.objects.all()
form = forms.ConceptComponentForm
@register_model_view(ConceptComponent, 'delete')
class ConceptComponentDeleteView(generic.ObjectDeleteView):
queryset = ConceptComponent.objects.all()
@register_model_view(ConceptComponent, 'bulk_delete', path='delete', detail=False)
class ConceptComponentBulkDeleteView(generic.BulkDeleteView):
queryset = ConceptComponent.objects.select_related('device')
filterset = filtersets.ConceptComponentFilterSet
table = tables.ConceptComponentTable
#
# Concept cables
#
@register_model_view(ConceptCable, 'list', path='', detail=False)
class ConceptCableListView(generic.ObjectListView):
queryset = ConceptCable.objects.select_related(
'termination_a', 'termination_a__device', 'termination_b', 'termination_b__device'
)
table = tables.ConceptCableTable
filterset = filtersets.ConceptCableFilterSet
filterset_form = forms.ConceptCableFilterForm
@register_model_view(ConceptCable)
class ConceptCableView(generic.ObjectView):
queryset = ConceptCable.objects.select_related(
'termination_a', 'termination_a__device', 'termination_b', 'termination_b__device'
)
template_name = 'netbox_rack_concept/conceptcable.html'
@register_model_view(ConceptCable, 'add', detail=False)
@register_model_view(ConceptCable, 'edit')
class ConceptCableEditView(generic.ObjectEditView):
queryset = ConceptCable.objects.all()
form = forms.ConceptCableForm
@register_model_view(ConceptCable, 'delete')
class ConceptCableDeleteView(generic.ObjectDeleteView):
queryset = ConceptCable.objects.all()
@register_model_view(ConceptCable, 'bulk_delete', path='delete', detail=False)
class ConceptCableBulkDeleteView(generic.BulkDeleteView):
queryset = ConceptCable.objects.select_related('termination_a', 'termination_b')
filterset = filtersets.ConceptCableFilterSet
table = tables.ConceptCableTable