Fix admin actions

This commit is contained in:
Sander Steffann 2020-04-16 15:34:34 +02:00
parent 19e19639fd
commit 7b514942c0

View file

@ -4,6 +4,7 @@ from django.contrib import admin, messages
from django.contrib.admin.filters import SimpleListFilter from django.contrib.admin.filters import SimpleListFilter
from django.contrib.admin.options import ModelAdmin from django.contrib.admin.options import ModelAdmin
from django.db.models import QuerySet from django.db.models import QuerySet
from django.db.models.query_utils import Q
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -64,15 +65,16 @@ class ZoneAdmin(admin.ModelAdmin):
more_specifics = Zone.objects.filter(name__endswith=zone.name).exclude(pk=zone.pk) more_specifics = Zone.objects.filter(name__endswith=zone.name).exclude(pk=zone.pk)
# Find all IPAddress objects in this zone but not in the more-specifics # Find all IPAddress objects in this zone but not in the more-specifics
addresses = IPAddress.objects.filter(dns_name__endswith=zone.name) addresses = IPAddress.objects.filter(Q(dns_name__endswith=zone.name) |
Q(dns_name__endswith=zone.name.rstrip('.')))
for more_specific in more_specifics: for more_specific in more_specifics:
addresses = addresses.exclude(dns_name__endswith=more_specific.name) addresses = addresses.exclude(Q(dns_name__endswith=more_specific.name) |
Q(dns_name__endswith=more_specific.name.rstrip('.')))
for address in addresses: for address in addresses:
if address.dns_name: if address.dns_name:
update_dns.delay( update_dns.delay(
new_address=address.address.ip, new_record=address,
new_dns_name=address.dns_name,
skip_reverse=True skip_reverse=True
) )
counter += 1 counter += 1
@ -104,8 +106,7 @@ class ReverseZoneAdmin(admin.ModelAdmin):
for address in addresses: for address in addresses:
if address.dns_name: if address.dns_name:
update_dns.delay( update_dns.delay(
new_address=address.address.ip, new_record=address,
new_dns_name=address.dns_name,
skip_forward=True skip_forward=True
) )
counter += 1 counter += 1