Skip to content

Commit

Permalink
Initial work on #951
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Apr 19, 2017
1 parent 401357b commit dc9b96d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
13 changes: 8 additions & 5 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re

from mptt.forms import TreeNodeChoiceField
import re

from django import forms
from django.contrib.postgres.forms.array import SimpleArrayField
Expand All @@ -21,9 +20,9 @@
DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED,
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType,
Interface, IFACE_FF_CHOICES, IFACE_FF_LAG, IFACE_ORDERING_CHOICES, InterfaceConnection, InterfaceTemplate,
Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, RACK_TYPE_CHOICES,
RACK_WIDTH_CHOICES, Rack, RackGroup, RackReservation, RackRole, Region, Site, STATUS_CHOICES, SUBDEVICE_ROLE_CHILD,
SUBDEVICE_ROLE_PARENT, VIRTUAL_IFACE_TYPES
Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, RACK_FACE_CHOICES,
RACK_TYPE_CHOICES, RACK_WIDTH_CHOICES, Rack, RackGroup, RackReservation, RackRole, Region, Site, STATUS_CHOICES,
SUBDEVICE_ROLE_CHILD, SUBDEVICE_ROLE_PARENT, VIRTUAL_IFACE_TYPES,
)


Expand Down Expand Up @@ -302,6 +301,10 @@ class RackFilterForm(BootstrapMixin, CustomFieldFilterForm):
)


class RackElevationFilterForm(RackFilterForm):
face = forms.ChoiceField(choices=RACK_FACE_CHOICES, required=False)


#
# Rack reservations
#
Expand Down
1 change: 1 addition & 0 deletions netbox/dcim/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

# Racks
url(r'^racks/$', views.RackListView.as_view(), name='rack_list'),
url(r'^rack-elevations/$', views.RackElevationListView.as_view(), name='rack_elevation_list'),
url(r'^racks/add/$', views.RackEditView.as_view(), name='rack_add'),
url(r'^racks/import/$', views.RackBulkImportView.as_view(), name='rack_import'),
url(r'^racks/edit/$', views.RackBulkEditView.as_view(), name='rack_bulk_edit'),
Expand Down
30 changes: 30 additions & 0 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from circuits.models import Circuit
from extras.models import Graph, TopologyMap, GRAPH_TYPE_INTERFACE, GRAPH_TYPE_SITE
from utilities.forms import ConfirmationForm
from utilities.paginator import EnhancedPaginator
from utilities.views import (
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
)
Expand Down Expand Up @@ -291,6 +292,35 @@ class RackListView(ObjectListView):
template_name = 'dcim/rack_list.html'


class RackElevationListView(View):
"""
Display a set of rack elevations side-by-side.
"""

def get(self, request):

racks = Rack.objects.select_related(
'site', 'group', 'tenant', 'role'
).prefetch_related(
'devices__device_type'
)
racks = filters.RackFilter(request.GET, racks).qs
total_count = racks.count()

# Determine rack face
if request.GET.get('face') == '1':
face_id = 1
else:
face_id = 0

return render(request, 'dcim/rack_elevation_list.html', {
'racks': racks[:50],
'total_count': total_count,
'face_id': face_id,
'filter_form': forms.RackElevationFilterForm(request.GET),
})


def rack(request, pk):

rack = get_object_or_404(Rack.objects.select_related('site__region', 'tenant__group', 'group', 'role'), pk=pk)
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Racks <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{% url 'dcim:rack_list' %}"><i class="fa fa-search" aria-hidden="true"></i> Racks</a></li>
<li><a href="{% url 'dcim:rack_elevation_list' %}"><i class="fa fa-bars" aria-hidden="true"></i> Rack Elevations</a></li>
{% if perms.dcim.add_rack %}
<li><a href="{% url 'dcim:rack_add' %}"><i class="fa fa-plus" aria-hidden="true"></i> Add a Rack</a></li>
<li><a href="{% url 'dcim:rack_import' %}"><i class="fa fa-download" aria-hidden="true"></i> Import Racks</a></li>
Expand Down
46 changes: 46 additions & 0 deletions netbox/templates/dcim/rack_elevation_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends '_base.html' %}
{% load helpers %}

{% block content %}
<h1>{% block title %}Rack Elevations{% endblock %}</h1>
<div class="row">
{% if racks %}
<div class="col-md-9">
<div style="white-space: nowrap; overflow-x: scroll;">
{% for rack in racks %}
<div style="display: inline-block; width: 266px">
<div class="rack_header">
<h4>{{ rack.name }}</h4>
</div>
{% if face_id %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_rear_elevation secondary_face=rack.get_front_elevation face_id=1 %}
{% else %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_front_elevation secondary_face=rack.get_rear_elevation face_id=0 %}
{% endif %}
<div class="clearfix"></div>
<div class="rack_header">
<h4>{{ rack.name }}</h4>
</div>
</div>
{% endfor %}
</div>
<p class="text-right text-muted">Showing {{ racks.count }} of {{ total_count }} racks</p>
</div>
{% else %}
<div class="col-md-9">
<p>No racks found</p>
</div>
{% endif %}
<div class="col-md-3">
{% include 'inc/search_panel.html' %}
</div>
</div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
$(function() {
$('[data-toggle="popover"]').popover()
})
</script>
{% endblock %}

0 comments on commit dc9b96d

Please sign in to comment.