Commit c485b7d3 by Kálmán Viktor

network: confirmation for domain delete

parent 089ff40c
...@@ -17,6 +17,7 @@ from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm, ...@@ -17,6 +17,7 @@ from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
from django.contrib import messages from django.contrib import messages
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.db.models import Q
from itertools import chain from itertools import chain
import json import json
...@@ -148,6 +149,50 @@ class DomainDelete(DeleteView): ...@@ -148,6 +149,50 @@ class DomainDelete(DeleteView):
else: else:
return reverse_lazy('network.domain_list') return reverse_lazy('network.domain_list')
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
if unicode(self.object) != request.POST.get('confirm'):
messages.error(request, _("Object name does not match!"))
return self.get(request, *args, **kwargs)
response = super(DomainDelete, self).delete(request, *args, **kwargs)
messages.success(request, _("Domain successfully deleted!"))
return response
def get_context_data(self, **kwargs):
context = super(DomainDelete, self).get_context_data(**kwargs)
deps = []
# vlans
vlans = Vlan.objects.filter(domain=self.object).all()
if len(vlans) > 0:
deps.append({
'name': 'Vlans',
'data': vlans
})
# hosts
hosts = Host.objects.filter(vlan__in=deps[0]['data'])
if len(hosts) > 0:
deps.append({
'name': 'Hosts',
'data': hosts
})
# records
records = Record.objects.filter(
Q(domain=self.object) | Q(host__in=deps[1]['data'])
)
if len(records) > 0:
deps.append({
'name': 'Records',
'data': records
})
context['deps'] = deps
context['confirmation'] = True
return context
class GroupList(SingleTableView): class GroupList(SingleTableView):
model = Group model = Group
...@@ -461,7 +506,7 @@ class VlanDelete(DeleteView): ...@@ -461,7 +506,7 @@ class VlanDelete(DeleteView):
deps = [] deps = []
# hosts # hosts
hosts = Host.objects.filter(vlan=self.get_object).all() hosts = Host.objects.filter(vlan=self.object).all()
if len(hosts) > 0: if len(hosts) > 0:
deps.append({ deps.append({
'name': 'Hosts', 'name': 'Hosts',
......
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