Commit 36726958 by Kálmán Viktor

network: fix missing records when deleting domain

parent 16250135
...@@ -18,7 +18,8 @@ from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm, ...@@ -18,7 +18,8 @@ from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
from django.contrib import messages from django.contrib import messages
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.db.models import Q # from django.db.models import Q
from operator import itemgetter
from itertools import chain from itertools import chain
import json import json
...@@ -206,14 +207,26 @@ class DomainDelete(DeleteView): ...@@ -206,14 +207,26 @@ class DomainDelete(DeleteView):
# records # records
records = Record.objects.filter( records = Record.objects.filter(
Q(domain=self.object) | Q(host__in=deps[1]['data']) host__in=deps[1]['data']
# Q(domain=self.object) | (host__in=deps[1]['data'])
) )
if len(records) > 0: if len(records) > 0:
deps.append({ deps.append({
'name': 'Records', 'name': 'Records from hosts',
'data': records 'data': records
}) })
records = Record.objects.filter(domain=self.object)
if len(records) > 0:
# to filter out doubles (records from hosts and domains)
indexes = map(itemgetter('name'), deps)
n = indexes.index('Records from hosts') if len(indexes) > 0 else 0
deps.append({
'name': 'Records only from the domain',
'data': records.exclude(pk__in=deps[n]['data']) if n > 0
else records
})
context['deps'] = deps context['deps'] = deps
context['confirmation'] = True context['confirmation'] = True
return context return context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment