Files
netbox-plugin-dns-bridge/netbox_dns_bridge/views.py
T
sven 6be7359c27 Replace global IntegerKeyValueSetting with per-view CatalogZone model
Track the catalog zone SOA serial per view instead of a single global value.
The new CatalogZone model has a 1:1 FK to netbox_dns.models.View and its own
soa_serial field; each view's catalog zone now increments independently. The
existing global serial is preserved during migration by copying it into every
view's new CatalogZone row.

Change CatalogZoneMemberIdentifier.name from globally unique to unique per
catalog zone (UniqueConstraint(name, catalog_zone)) and add a catalog_zone FK
to enforce it.

Remove the dns-settings management command, which was a generic interface over
the now-removed IntegerKeyValueSetting model.

Increment both catalog zone serials when a zone moves between views: the old
view's catalog zone loses a member and the new view's gains one, so both must
be bumped. Also refresh the member identifier's catalog_zone FK on a view move
so it does not go stale. The pre_save handler now captures _old_view_id and the
post_save handler detects view changes, increments the old view's serial inside
on_commit (before the new view's), and re-creates the identifier.

AI generated, code manually verified.
2026-09-02 12:01:54 +02:00

50 lines
1.5 KiB
Python

from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views import View
import netbox_dns.models
from netbox.views.generic import ObjectListView
from .filtersets import ZoneFilterSet
from .forms import CatalogZoneFilterForm
from .models import CatalogZone, SeenTransferClients
from .tables import CatalogZoneTable
@method_decorator(
user_passes_test(lambda u: u.is_superuser), name="dispatch"
)
class CatzOverviewView(ObjectListView):
queryset = netbox_dns.models.Zone.objects.select_related(
"view", "catz_identifier"
).order_by("view__name", "name")
table = CatalogZoneTable
filterset = ZoneFilterSet
filterset_form = CatalogZoneFilterForm
template_name = "netbox_dns_bridge/catz_overview.html"
actions = ()
def get_extra_context(self, request):
context = super().get_extra_context(request)
context["catalog_zones"] = CatalogZone.objects.select_related(
"view"
).order_by("view__name")
return context
@method_decorator(
user_passes_test(lambda u: u.is_superuser), name="dispatch"
)
class NotifyOverviewView(View):
template_name = "netbox_dns_bridge/notify_overview.html"
def get(self, request):
seen_clients = (
SeenTransferClients.objects.select_related("view")
.all()
.order_by("source_ip")
)
context = {"seen_clients": seen_clients}
return render(request, self.template_name, context)