From 4ae65f39eab803cb5f4e4c90ee62fbc7c659c34f Mon Sep 17 00:00:00 2001 From: Peter Eckel Date: Wed, 28 Aug 2024 21:58:02 +0200 Subject: [PATCH] Added the contacts feature to Zone, Record, View and NameServer Co-authored-by: 12158973+ThomasADavis@users.noreply.github.com --- netbox_dns/models/nameserver.py | 3 ++- netbox_dns/models/record.py | 3 ++- netbox_dns/models/view.py | 3 ++- netbox_dns/models/zone.py | 3 ++- netbox_dns/urls/nameserver.py | 6 ++++++ netbox_dns/urls/record.py | 6 ++++++ netbox_dns/urls/view.py | 2 ++ netbox_dns/urls/zone.py | 2 ++ netbox_dns/views/nameserver.py | 7 +++++++ netbox_dns/views/record.py | 8 ++++++++ netbox_dns/views/view.py | 8 ++++++++ netbox_dns/views/zone.py | 7 +++++++ 12 files changed, 54 insertions(+), 4 deletions(-) diff --git a/netbox_dns/models/nameserver.py b/netbox_dns/models/nameserver.py index 99e55f57..4e8c568f 100644 --- a/netbox_dns/models/nameserver.py +++ b/netbox_dns/models/nameserver.py @@ -7,6 +7,7 @@ from netbox.models import NetBoxModel from netbox.search import SearchIndex, register_search +from netbox.models.features import ContactsMixin from netbox_dns.utilities import ( name_to_unicode, @@ -26,7 +27,7 @@ ) -class NameServer(ObjectModificationMixin, NetBoxModel): +class NameServer(ObjectModificationMixin, ContactsMixin, NetBoxModel): name = models.CharField( unique=True, max_length=255, diff --git a/netbox_dns/models/record.py b/netbox_dns/models/record.py index dc67e1ae..01a70146 100644 --- a/netbox_dns/models/record.py +++ b/netbox_dns/models/record.py @@ -9,6 +9,7 @@ from django.urls import reverse from netbox.models import NetBoxModel +from netbox.models.features import ContactsMixin from netbox.search import SearchIndex, register_search from netbox.plugins.utils import get_plugin_config from utilities.querysets import RestrictedQuerySet @@ -62,7 +63,7 @@ def get_queryset(self): ) -class Record(ObjectModificationMixin, NetBoxModel): +class Record(ObjectModificationMixin, ContactsMixin, NetBoxModel): ACTIVE_STATUS_LIST = (RecordStatusChoices.STATUS_ACTIVE,) unique_ptr_qs = Q( diff --git a/netbox_dns/models/view.py b/netbox_dns/models/view.py index 5760f4d7..faf65208 100644 --- a/netbox_dns/models/view.py +++ b/netbox_dns/models/view.py @@ -3,6 +3,7 @@ from django.core.exceptions import ValidationError from netbox.models import NetBoxModel +from netbox.models.features import ContactsMixin from netbox.search import SearchIndex, register_search from netbox.context import current_request from utilities.exceptions import AbortRequest @@ -16,7 +17,7 @@ ) -class View(ObjectModificationMixin, NetBoxModel): +class View(ObjectModificationMixin, ContactsMixin, NetBoxModel): name = models.CharField( unique=True, max_length=255, diff --git a/netbox_dns/models/zone.py b/netbox_dns/models/zone.py index 1d6cb091..83644d66 100644 --- a/netbox_dns/models/zone.py +++ b/netbox_dns/models/zone.py @@ -19,6 +19,7 @@ from django.conf import settings from netbox.models import NetBoxModel +from netbox.models.features import ContactsMixin from netbox.search import SearchIndex, register_search from netbox.plugins.utils import get_plugin_config from utilities.querysets import RestrictedQuerySet @@ -67,7 +68,7 @@ def get_queryset(self): ) -class Zone(ObjectModificationMixin, NetBoxModel): +class Zone(ObjectModificationMixin, ContactsMixin, NetBoxModel): ACTIVE_STATUS_LIST = (ZoneStatusChoices.STATUS_ACTIVE,) def __init__(self, *args, **kwargs): diff --git a/netbox_dns/urls/nameserver.py b/netbox_dns/urls/nameserver.py index 91433264..7abc024f 100644 --- a/netbox_dns/urls/nameserver.py +++ b/netbox_dns/urls/nameserver.py @@ -13,6 +13,7 @@ NameServerBulkDeleteView, NameServerZoneListView, NameServerSOAZoneListView, + NameServerContactsView, ) nameserver_urlpatterns = [ @@ -44,6 +45,11 @@ NameServerDeleteView.as_view(), name="nameserver_delete", ), + path( + "nameservers//contacts/", + NameServerContactsView.as_view(), + name="nameserver_contacts", + ), path( "nameservers//journal/", ObjectJournalView.as_view(), diff --git a/netbox_dns/urls/record.py b/netbox_dns/urls/record.py index 93000c49..d172e2f1 100644 --- a/netbox_dns/urls/record.py +++ b/netbox_dns/urls/record.py @@ -11,6 +11,7 @@ RecordBulkImportView, RecordBulkEditView, RecordBulkDeleteView, + RecordContactsView, ManagedRecordListView, ) @@ -23,6 +24,11 @@ path("records//", RecordView.as_view(), name="record"), path("records//edit/", RecordEditView.as_view(), name="record_edit"), path("records//delete/", RecordDeleteView.as_view(), name="record_delete"), + path( + "records//contacts/", + RecordContactsView.as_view(), + name="record_contacts", + ), path( "records//journal/", ObjectJournalView.as_view(), diff --git a/netbox_dns/urls/view.py b/netbox_dns/urls/view.py index c7eb3da6..a5720b1d 100644 --- a/netbox_dns/urls/view.py +++ b/netbox_dns/urls/view.py @@ -11,6 +11,7 @@ ViewBulkImportView, ViewBulkEditView, ViewBulkDeleteView, + ViewContactsView, ViewZoneListView, ) @@ -23,6 +24,7 @@ path("views//", ViewView.as_view(), name="view"), path("views//edit/", ViewEditView.as_view(), name="view_edit"), path("views//delete/", ViewDeleteView.as_view(), name="view_delete"), + path("views//contacts/", ViewContactsView.as_view(), name="view_contacts"), path("views//zones/", ViewZoneListView.as_view(), name="view_zones"), path( "views//journal/", diff --git a/netbox_dns/urls/zone.py b/netbox_dns/urls/zone.py index dc9979fd..ace91710 100644 --- a/netbox_dns/urls/zone.py +++ b/netbox_dns/urls/zone.py @@ -11,6 +11,7 @@ ZoneBulkImportView, ZoneBulkEditView, ZoneBulkDeleteView, + ZoneContactsView, ZoneRecordListView, ZoneManagedRecordListView, ZoneRegistrationView, @@ -27,6 +28,7 @@ path("zones//", ZoneView.as_view(), name="zone"), path("zones//delete/", ZoneDeleteView.as_view(), name="zone_delete"), path("zones//edit/", ZoneEditView.as_view(), name="zone_edit"), + path("zones//contacts/", ZoneContactsView.as_view(), name="zone_contacts"), path("zones//records/", ZoneRecordListView.as_view(), name="zone_records"), path( "zones//managedrecords/", diff --git a/netbox_dns/views/nameserver.py b/netbox_dns/views/nameserver.py index d6cc264d..a02aea9e 100644 --- a/netbox_dns/views/nameserver.py +++ b/netbox_dns/views/nameserver.py @@ -2,6 +2,7 @@ from netbox.views import generic from utilities.views import ViewTab, register_model_view +from tenancy.views import ObjectContactsView from netbox_dns.filtersets import NameServerFilterSet, ZoneFilterSet from netbox_dns.forms import ( @@ -24,6 +25,7 @@ "NameServerBulkDeleteView", "NameServerZoneListView", "NameServerSOAZoneListView", + "NameServerContactsView", ) @@ -77,6 +79,11 @@ class NameServerBulkDeleteView(generic.BulkDeleteView): table = NameServerTable +@register_model_view(NameServer, "contacts") +class NameServerContactsView(ObjectContactsView): + queryset = NameServer.objects.all() + + @register_model_view(NameServer, "zones") class NameServerZoneListView(generic.ObjectChildrenView): queryset = NameServer.objects.all().prefetch_related("zones") diff --git a/netbox_dns/views/record.py b/netbox_dns/views/record.py index d2123abe..a04777b5 100644 --- a/netbox_dns/views/record.py +++ b/netbox_dns/views/record.py @@ -1,6 +1,8 @@ from dns import name as dns_name from netbox.views import generic +from utilities.views import register_model_view +from tenancy.views import ObjectContactsView from netbox_dns.filtersets import RecordFilterSet from netbox_dns.forms import ( @@ -24,6 +26,7 @@ "RecordBulkImportView", "RecordBulkEditView", "RecordBulkDeleteView", + "RecordContactsView", ) @@ -155,3 +158,8 @@ class RecordBulkEditView(generic.BulkEditView): class RecordBulkDeleteView(generic.BulkDeleteView): queryset = Record.objects.filter(managed=False) table = RecordTable + + +@register_model_view(Record, "contacts") +class RecordContactsView(ObjectContactsView): + queryset = Record.objects.all() diff --git a/netbox_dns/views/view.py b/netbox_dns/views/view.py index 19b080a2..e8e33b8d 100644 --- a/netbox_dns/views/view.py +++ b/netbox_dns/views/view.py @@ -1,6 +1,8 @@ from utilities.views import ViewTab, register_model_view from netbox.views import generic +from utilities.views import register_model_view +from tenancy.views import ObjectContactsView from netbox_dns.models import View, Zone from netbox_dns.filtersets import ViewFilterSet, ZoneFilterSet @@ -16,6 +18,7 @@ "ViewBulkImportView", "ViewBulkEditView", "ViewBulkDeleteView", + "ViewContactsView", "ViewZoneListView", ) @@ -79,3 +82,8 @@ class ViewZoneListView(generic.ObjectChildrenView): def get_children(self, request, parent): return parent.zone_set + + +@register_model_view(View, "contacts") +class ViewContactsView(ObjectContactsView): + queryset = View.objects.all() diff --git a/netbox_dns/views/zone.py b/netbox_dns/views/zone.py index dfb4242e..ce83a146 100644 --- a/netbox_dns/views/zone.py +++ b/netbox_dns/views/zone.py @@ -2,6 +2,7 @@ from netbox.views import generic from utilities.views import ViewTab, register_model_view +from tenancy.views import ObjectContactsView from netbox_dns.filtersets import ZoneFilterSet, RecordFilterSet from netbox_dns.forms import ( @@ -26,6 +27,7 @@ "ZoneBulkImportView", "ZoneBulkEditView", "ZoneBulkDeleteView", + "ZoneContactsView", "ZoneRegistrationView", "ZoneRecordListView", "ZoneManagedRecordListView", @@ -201,3 +203,8 @@ class ZoneChildZoneListView(generic.ObjectChildrenView): def get_children(self, request, parent): return parent.child_zones + + +@register_model_view(Zone, "contacts") +class ZoneContactsView(ObjectContactsView): + queryset = Zone.objects.all()