Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support netbox v3 #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dev_setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
+ clone netbox_topology_views repo
+ create venv: `/usr/bin/python3 -m venv venv`
+ activate venv: `source venv/bin/activate`
+ install deps: `pip3 install -r requirements.txt`
+ install build tools: `python3 -m pip install --upgrade build setuptools wheel`

+ install deps: `pip3 install -r requirements.txt` (in the netbox folder)

# Build
+ build the package: `python3 setup.py develop`
Expand Down
88 changes: 67 additions & 21 deletions netbox_topology_views/templates/netbox_topology_views/index.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,75 @@
{% extends 'base.html' %}
{% load static %}
{% extends 'base/layout.html' %}
{% load buttons %}
{% load helpers %}
{% load render_table from django_tables2 %}
{% load static %}
{% load form_helpers %}

{% block content %}

{% block title %}Topology Views{% endblock %}

{% block controls %}
<div class="controls">
<div class="control-group">
{% block extra_controls %}{% endblock %}
<a id="btnDownloadImage" class="btn btn-sm btn-info">
<i class="mdi mdi-download"></i>
Download
</a>
<a id="btnFullView" class="btn btn-sm btn-info disabled" target="_blank">
<i class="mdi mdi-share"></i>
Share
</a>
</div>
</div>
{% endblock controls %}

{% block tabs %}
<ul class="nav nav-tabs px-3">
{% block tab_items %}
<li class="nav-item" role="presentation">
<button class="nav-link active" id="network-tab" data-bs-toggle="tab" data-bs-target="#networks" type="button" role="tab" aria-controls="filters-form" aria-selected="true">
Network
</button>
</li>
{% if filter_form %}
<li class="nav-item" role="presentation">
<button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
Filters
{% if filter_form %}{% badge filter_form.changed_data|length bg_class="primary" %}{% endif %}
</button>
</li>
{% endif %}
{% endblock tab_items %}
</ul>
{% endblock tabs %}


{% block content-wrapper %}
{% with config=settings.PLUGINS_CONFIG.netbox_topology_views %}
<link rel="stylesheet" href="{% static 'netbox_topology_views/css/vendor.css' %}">
<link rel="stylesheet" href="{% static 'netbox_topology_views/css/app.css' %}">
<div class="tab-content">

<div class="tab-pane show active" id="networks" role="tabpanel" aria-labelledby="network-tab">
</div>


{% if filter_form %}
<div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{% include 'inc/filter_list.html' %}
</div>
{% endif %}

</div>

{% endwith %}
{% endblock content-wrapper %}


{% block content %}

<div class="row ">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Network</strong> <span id="status"></span>
<div class="buttons pull-right">
<a id="btnDownloadImage" class="btn btn-xs btn-info">
<i class="mdi mdi-download"></i>
</a>
<a id="btnFullView" class="btn btn-xs btn-info disabled" target="_blank">
<i class="mdi mdi-share"></i>
</a>
</div>
</div>
<div class="panel-body">
<div id="visgraph" class=""></div>
</div>
Expand Down Expand Up @@ -71,7 +120,7 @@

</div>

{% if config.allow_coordinates_saving == True %}

<div class="panel panel-default mt-3">
<div class="panel-heading">
<strong>Settings</strong>
Expand All @@ -86,17 +135,14 @@
</div>
</div>
</div>
{% endif %}

</div>
</div>

{% endwith %}
{% endblock %}

{% block javascript %}

<script src="{% static 'netbox_topology_views/js/vendor.js' %}"></script>
<script src="{% static 'netbox_topology_views/js/app.js' %}"></script>

<script type="application/javascript"> iniPlotboxIndex()</script>

Expand Down
20 changes: 17 additions & 3 deletions netbox_topology_views/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
from django.shortcuts import get_object_or_404, render
from django.shortcuts import render
from django.views.generic import View
from django.contrib.auth.mixins import PermissionRequiredMixin
from . import filtersets, forms
from dcim.models import Device

class TopologyHomeView(PermissionRequiredMixin, View):
permission_required = ('dcim.view_site', 'dcim.view_device')

filterset = filtersets.TopologyHomeFilterSet
filterset_form = forms.TopologyHomeFilterForm

"""
Show the home page
"""
def get(self, request):
return render(request, 'netbox_topology_views/index.html')
def get(self, request):

self.queryset = Device.objects.none()
if self.filterset:
self.queryset = self.filterset(request.GET, self.queryset).qs

context = {
'filter_form': self.filterset_form(request.GET,label_suffix='') if self.filterset_form else None,
}

return render(request, 'netbox_topology_views/index.html', context)

class TopologyFullView(PermissionRequiredMixin, View):
permission_required = ('dcim.view_site', 'dcim.view_device')
Expand Down