Skip to content

Commit

Permalink
Added a "Related NetBox DNS Objects" pane to the tenant view
Browse files Browse the repository at this point in the history
  • Loading branch information
peteeckel committed Sep 18, 2023
1 parent dfbe6ed commit 4648cd8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
39 changes: 37 additions & 2 deletions netbox_dns/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from extras.plugins.utils import get_plugin_config
from extras.plugins import PluginTemplateExtension

from netbox_dns.models import Record, RecordTypeChoices, Zone
from netbox_dns.models import Record, RecordTypeChoices, Zone, View, NameServer
from netbox_dns.tables import RelatedRecordTable, RelatedZoneTable


Expand Down Expand Up @@ -61,5 +61,40 @@ def full_width_page(self):
)


class RelatedDNSObjects(PluginTemplateExtension):
model = "tenancy.tenant"

def left_page(self):
obj = self.context.get("object")
request = self.context.get("request")

related_dns_models = (
(
View.objects.restrict(request.user, "view").filter(tenant=obj),
"tenant_id",
),
(
NameServer.objects.restrict(request.user, "view").filter(tenant=obj),
"tenant_id",
),
(
Zone.objects.restrict(request.user, "view").filter(tenant=obj),
"tenant_id",
),
(
Record.objects.restrict(request.user, "view").filter(tenant=obj),
"tenant_id",
),
)

return self.render(
"netbox_dns/related_dns_objects.html",
extra_context={
"related_dns_models": related_dns_models,
},
)


template_extensions = [RelatedDNSObjects]
if get_plugin_config("netbox_dns", "feature_ipam_integration"):
template_extensions = [RelatedDNSRecords, RelatedDNSPointerZones]
template_extensions += [RelatedDNSRecords, RelatedDNSPointerZones]
21 changes: 21 additions & 0 deletions netbox_dns/templates/netbox_dns/related_dns_objects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% load helpers %}

<div class="card">
<h5 class="card-header">Related NetBox DNS Objects</h5>
<ul class="list-group list-group-flush">
{% for qs, filter_param in related_dns_models %}
{% with viewname=qs.model|viewname:"list" %}
<a href="{% url viewname %}?{{ filter_param }}={{ object.pk }}" class="list-group-item list-group-item-action d-flex justify-content-between">
{{ qs.model|meta:"verbose_name_plural"|bettertitle }}
{% with count=qs.count %}
{% if count %}
<span class="badge bg-primary rounded-pill">{{ count }}</span>
{% else %}
<span class="badge bg-light rounded-pill">&mdash;</span>
{% endif %}
{% endwith %}
</a>
{% endwith %}
{% endfor %}
</ul>
</div>

0 comments on commit 4648cd8

Please sign in to comment.