From 2525eefefdaf0c5de5b506e357f8f4de61b007cd Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 25 Jan 2023 20:45:30 -0500 Subject: [PATCH] Move rack reservations panel to separate tab --- netbox/dcim/views.py | 22 +++++- netbox/templates/dcim/rack.html | 73 +------------------- netbox/templates/dcim/rack/base.html | 23 ++++++ netbox/templates/dcim/rack/reservations.html | 43 ++++++++++++ 4 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 netbox/templates/dcim/rack/base.html create mode 100644 netbox/templates/dcim/rack/reservations.html diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 35ab0ee20..095314e7b 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -677,8 +677,6 @@ class RackView(generic.ObjectView): next_rack = peer_racks.filter(_name__gt=instance._name).first() prev_rack = peer_racks.filter(_name__lt=instance._name).reverse().first() - reservations = RackReservation.objects.restrict(request.user, 'view').filter(rack=instance) - # Determine any additional parameters to pass when embedding the rack elevations svg_extra = '&'.join([ f'highlight=id:{pk}' for pk in request.GET.getlist('device') @@ -686,7 +684,6 @@ class RackView(generic.ObjectView): return { 'related_models': related_models, - 'reservations': reservations, 'nonracked_devices': nonracked_devices, 'next_rack': next_rack, 'prev_rack': prev_rack, @@ -694,6 +691,25 @@ class RackView(generic.ObjectView): } +@register_model_view(Rack, 'reservations') +class RackRackReservationsView(generic.ObjectChildrenView): + queryset = Rack.objects.all() + child_model = RackReservation + table = tables.RackReservationTable + filterset = filtersets.RackReservationFilterSet + template_name = 'dcim/rack/reservations.html' + tab = ViewTab( + label=_('Reservations'), + badge=lambda obj: obj.reservations.count(), + permission='dcim.view_rackreservation', + weight=510, + hide_if_empty=True + ) + + def get_children(self, request, parent): + return parent.reservations.restrict(request.user, 'view') + + @register_model_view(Rack, 'edit') class RackEditView(generic.ObjectEditView): queryset = Rack.objects.all() diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index c155f2796..9cb046b4e 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -1,31 +1,9 @@ -{% extends 'generic/object.html' %} +{% extends 'dcim/rack/base.html' %} {% load buttons %} {% load helpers %} {% load static %} {% load plugins %} -{% block title %}Rack {{ object }}{% endblock %} - -{% block breadcrumbs %} - {{ block.super }} - - {% if object.location %} - {% for location in object.location.get_ancestors %} - - {% endfor %} - - {% endif %} -{% endblock %} - -{% block extra_controls %} - - Previous - - - Next - -{% endblock %} - {% block content %}
@@ -187,55 +165,6 @@ {% include 'inc/panels/tags.html' %} {% include 'inc/panels/comments.html' %} {% include 'inc/panels/image_attachments.html' %} -
-
- Reservations -
-
- {% if reservations %} - - - - - - - - {% for resv in reservations %} - - - - - - - {% endfor %} -
UnitsTenantDescription
{{ resv|linkify:"unit_list" }}{{ resv.tenant|linkify|placeholder }} - {{ resv.description }}
- {{ resv.user }} · {{ resv.created|annotated_date }} -
- {% if perms.dcim.change_rackreservation %} - - - - {% endif %} - {% if perms.dcim.delete_rackreservation %} - - - - {% endif %} -
- {% else %} -
None
- {% endif %} -
- {% if perms.dcim.add_rackreservation %} - - {% endif %} -
{% plugin_left_page object %}
diff --git a/netbox/templates/dcim/rack/base.html b/netbox/templates/dcim/rack/base.html new file mode 100644 index 000000000..8ac7b70d0 --- /dev/null +++ b/netbox/templates/dcim/rack/base.html @@ -0,0 +1,23 @@ +{% extends 'generic/object.html' %} + +{% block title %}Rack {{ object }}{% endblock %} + +{% block breadcrumbs %} + {{ block.super }} + + {% if object.location %} + {% for location in object.location.get_ancestors %} + + {% endfor %} + + {% endif %} +{% endblock %} + +{% block extra_controls %} + + Previous + + + Next + +{% endblock %} diff --git a/netbox/templates/dcim/rack/reservations.html b/netbox/templates/dcim/rack/reservations.html new file mode 100644 index 000000000..fb357e592 --- /dev/null +++ b/netbox/templates/dcim/rack/reservations.html @@ -0,0 +1,43 @@ +{% extends 'dcim/rack/base.html' %} +{% load helpers %} + +{% block content %} + {% include 'inc/table_controls_htmx.html' with table_modal="RackReservationTable_config" %} + +
+ {% csrf_token %} + +
+
+ {% include 'htmx/table.html' %} +
+
+ +
+
+ {% if 'bulk_edit' in actions %} + + {% endif %} + {% if 'bulk_delete' in actions %} + + {% endif %} +
+ {% if perms.dcim.add_rackreservation %} + + {% endif %} +
+
+{% endblock %} + +{% block modals %} + {{ block.super }} + {% table_config_form table %} +{% endblock modals %}