improved views and templates
This commit is contained in:
@@ -7,11 +7,12 @@ class CoordinateGroupListTable(NetBoxTable):
|
||||
name = tables.Column(
|
||||
linkify=True
|
||||
)
|
||||
devices = tables.Column()
|
||||
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = CoordinateGroup
|
||||
fields = ('pk', 'name', 'description')
|
||||
default_columns = ('name', 'description')
|
||||
fields = ('pk', 'id', 'name', 'description', 'devices')
|
||||
default_columns = ('name', 'description', 'devices')
|
||||
|
||||
class CoordinateListTable(NetBoxTable):
|
||||
group = tables.Column(
|
||||
@@ -24,6 +25,6 @@ class CoordinateListTable(NetBoxTable):
|
||||
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = Coordinate
|
||||
fields = ('pk', 'group', 'device', 'x', 'y')
|
||||
fields = ('pk', 'id', 'group', 'device', 'x', 'y')
|
||||
default_columns = ('id', 'group', 'device', 'x', 'y')
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{% extends 'generic/object.html' %}
|
||||
{% load helpers %}
|
||||
{% load plugins %}
|
||||
{% load render_table from django_tables2 %}
|
||||
|
||||
{% block title %}Topology Views Coordinates{% endblock title %}
|
||||
|
||||
@@ -16,11 +15,11 @@
|
||||
<table class="table table-hover attr-table">
|
||||
<tr>
|
||||
<th scope="row">Group</th>
|
||||
<td>{{ object.group }}</td>
|
||||
<td>{{ object.group|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Device</th>
|
||||
<td>{{ object.device }}</td>
|
||||
<td>{{ object.device|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">X-Coordinate</th>
|
||||
|
||||
@@ -32,4 +32,14 @@
|
||||
{% plugin_right_page object %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<div class="card">
|
||||
<h5 class="card-header">Coordinates</h5>
|
||||
<div class="card-body table-responsive">
|
||||
{% render_table coordinates_table %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.urls import path
|
||||
from django.views.generic.base import RedirectView
|
||||
|
||||
from netbox.views.generic import ObjectChangeLogView
|
||||
from . import models, views
|
||||
|
||||
# Define a list of URL patterns to be imported by NetBox. Each pattern maps a URL to
|
||||
@@ -17,7 +17,7 @@ urlpatterns = (
|
||||
path("coordinate-groups/<int:pk>/", views.CoordinateGroupView.as_view(), name="coordinategroup"),
|
||||
path("coordinate-groups/<int:pk>/edit/", views.CoordinateGroupEditView.as_view(), name="coordinategroup_edit"),
|
||||
path("coordinate-groups/<int:pk>/delete/", views.CoordinateGroupDeleteView.as_view(), name="coordinategroup_delete"),
|
||||
path("coordinate-groups/<int:pk>/changelog/", views.CoordinateGroupChangeLogView.as_view(), name="coordinategroup_changelog", kwargs={'model': models.CoordinateGroup}),
|
||||
path("coordinate-groups/<int:pk>/changelog/", ObjectChangeLogView.as_view(), name="coordinategroup_changelog", kwargs={'model': models.CoordinateGroup}),
|
||||
|
||||
# Coordinate
|
||||
path("coordinate/", views.CoordinateListView.as_view(), name="coordinate_list"),
|
||||
@@ -25,5 +25,5 @@ urlpatterns = (
|
||||
path("coordinate/<int:pk>/", views.CoordinateView.as_view(), name="coordinate"),
|
||||
path("coordinate/<int:pk>/edit/", views.CoordinateEditView.as_view(), name="coordinate_edit"),
|
||||
path("coordinate/<int:pk>/delete/", views.CoordinateDeleteView.as_view(), name="coordinate_delete"),
|
||||
path("coordinate/<int:pk>/changelog/", views.CoordinateChangeLogView.as_view(), name="coordinate_changelog", kwargs={'model': models.Coordinate}),
|
||||
path("coordinate/<int:pk>/changelog/", ObjectChangeLogView.as_view(), name="coordinate_changelog", kwargs={'model': models.Coordinate}),
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import Q, QuerySet
|
||||
from django.db.models import Q, QuerySet, Count
|
||||
from django.db.models.functions import Lower
|
||||
from django.http import HttpRequest, HttpResponseRedirect, QueryDict
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
@@ -825,6 +825,14 @@ class CoordinateGroupView(PermissionRequiredMixin, ObjectView):
|
||||
|
||||
queryset = CoordinateGroup.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
table = CoordinateListTable(instance.coordinate_set.all())
|
||||
table.configure(request)
|
||||
|
||||
return {
|
||||
'coordinates_table': table,
|
||||
}
|
||||
|
||||
class CoordinateGroupAddView(PermissionRequiredMixin, ObjectEditView):
|
||||
permission_required = 'netbox_topology_views.add_coordinategroup'
|
||||
|
||||
@@ -835,7 +843,9 @@ class CoordinateGroupAddView(PermissionRequiredMixin, ObjectEditView):
|
||||
class CoordinateGroupListView(PermissionRequiredMixin, ObjectListView):
|
||||
permission_required = 'netbox_topology_views.view_coordinategroup'
|
||||
|
||||
queryset = CoordinateGroup.objects.all()
|
||||
queryset = CoordinateGroup.objects.annotate(
|
||||
devices = Count('coordinate')
|
||||
)
|
||||
table = CoordinateGroupListTable
|
||||
template_name = 'netbox_topology_views/coordinategroup_list.html'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user