Commit 26220312 by Kálmán Viktor

network: object deletion

parent 3f4f880d
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
footer { footer {
margin-top: 40px; margin-top: 40px;
} }
.messagelist {
margin-top: 25px;
}
</style> </style>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
...@@ -50,16 +54,19 @@ ...@@ -50,16 +54,19 @@
</ul> </ul>
</div> </div>
</div> </div>
<div class="container">
{% block messages %} {% block messages %}
{% if messages %} {% if messages %}
<ul class="messagelist"> <div class="messagelist">
{% for message in messages %} {% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> <div class="alert
{% if message.tags %} alert-{% if message.tags == "error" %}danger{% else %}{{ message.tags }}{% endif %}{% endif %}">
{{ message }}
</div>
{% endfor %} {% endfor %}
</ul> </div>
{% endif %} {% endif %}
{% endblock messages %} {% endblock messages %}
<div class="container">
{% block content %} {% block content %}
<div class="alert-block">This is an abstract base template.</div> <div class="alert-block">This is an abstract base template.</div>
{% endblock %} {% endblock %}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.blacklist_delete pk=blacklist_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this blaclist</a>
<h1>{{ form.ipv4.value }} <small>{{ form.type.value }}</small></h1> <h1>{{ form.ipv4.value }} <small>{{ form.type.value }}</small></h1>
</div> </div>
<div class="row"> <div class="row">
......
{% extends "network/base.html" %}
{% load i18n %}
{% load l10n %}
{% block content %}
<div class="page-header">
<h2>Are you sure you want to delete <strong>"{% if to_delete %}{{ to_delete }}{% else %}{{ object }}{% endif %}"</strong>?</h2>
</div>
<form action="" method="post">{% csrf_token %}
{% if deps %}
<div class="alert alert-warning">
This action also <strong>removes</strong> the following
{% for dep in deps %}
<div class="alert">
<strong>{{ dep.name }}</strong>
<ul class="">
{{ dep.data|unordered_list }}
</ul>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-success">
No dependencies, safe to delete!
</div>
{% endif %}
<form action="" method="post">{% csrf_token %}
<input type="hidden" value="{{ request.GET.from }}" name="next" />
{% if confirmation %}
<label><p>
If you are really sure, type in the object's name!
<input type="text" name="confirm" class="form-control" placeholder="{{ object }}"/>
</p></label>
{% else %}
{% endif %}
<input type="submit" class="btn btn-danger btn-lg pull-right" value="Yes delete it!" />
</form>
{% endblock %}
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% load l10n %} {% load l10n %}
{% block content %} {% block content %}
<div class="page-heading"> <div class="page-header">
<h1>Remove <small></small></h1> <h1>Remove <small></small></h1>
</div> </div>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
......
{% extends "network/base.html" %}
{% load i18n %}
{% load l10n %}
{% block content %}
<div class="page-heading">
<h1>Delete <small>delete this rule</small></h1>
</div>
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete <strong>"{{ object }}"</strong>?</p>
<input type="hidden" value="{{ request.GET.from }}" name="next" />
<a href="{{ request.GET.from }}" class="btn btn-info">Back</a>
<input type="submit" class="btn btn-danger" value="Confirm" />
</form>
{% endblock %}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.domain_delete pk=domain_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this domain</a>
<h1>{{ form.name.value }} <small></small></h1> <h1>{{ form.name.value }} <small></small></h1>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.group_delete pk=group.pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this group</a>
<h1>{{ form.name.value }} <small>details of group</small></h1> <h1>{{ form.name.value }} <small>details of group</small></h1>
</div> </div>
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.host_delete pk=host_pk%}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this host</a>
<h1>{{ form.hostname.value }} <small>details of host</small></h1> <h1>{{ form.hostname.value }} <small>details of host</small></h1>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-8"> <div class="col-sm-8">
{% crispy form %} {% crispy form %}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.record_delete pk=record_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this record</a>
<h1>{{ fqdn }} <small>details of record</small></h1> <h1>{{ fqdn }} <small>details of record</small></h1>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.rule_delete pk=rule.pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this rule</a>
<h3> <h3>
{% with rule as record %} {% with rule as record %}
{% include "network/columns/host-rule.html" %} {% include "network/columns/host-rule.html" %}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.vlan_delete vid=vlan_vid %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this vlan</a>
<h1>{{ form.name.value }} <small>details of vlan</small></h1> <h1>{{ form.name.value }} <small>details of vlan</small></h1>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url network.vlangroup_delete pk=vlangroup_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> Delete this group</a>
<h1>{{ form.name.value }} <small>details of vlan group</small></h1> <h1>{{ form.name.value }} <small>details of vlan group</small></h1>
</div> </div>
......
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from .views import (IndexView, from .views import (IndexView,
HostList, HostDetail, HostCreate, HostList, HostDetail, HostCreate, HostDelete,
VlanList, VlanDetail, VlanList, VlanDetail, VlanDelete,
DomainList, DomainDetail, DomainList, DomainDetail, DomainDelete,
GroupList, GroupDetail, GroupList, GroupDetail, GroupDelete,
RecordList, RecordDetail, RecordCreate, RecordList, RecordDetail, RecordCreate, RecordDelete,
BlacklistList, BlacklistDetail, BlacklistList, BlacklistDetail, BlacklistDelete,
RuleList, RuleDetail, RuleDelete, RuleList, RuleDetail, RuleDelete,
VlanGroupList, VlanGroupDetail, VlanGroupList, VlanGroupDetail, VlanGroupDelete,
remove_host_group, add_host_group) remove_host_group, add_host_group)
js_info_dict = { js_info_dict = {
...@@ -22,28 +22,42 @@ urlpatterns = patterns( ...@@ -22,28 +22,42 @@ urlpatterns = patterns(
name='network.blacklist_list'), name='network.blacklist_list'),
url('^blacklists/(?P<pk>\d+)/$', BlacklistDetail.as_view(), url('^blacklists/(?P<pk>\d+)/$', BlacklistDetail.as_view(),
name='network.blacklist'), name='network.blacklist'),
url('^blacklists/delete/(?P<pk>\d+)/$', BlacklistDelete.as_view(),
name="network.blacklist_delete"),
url('^domains/$', DomainList.as_view(), name='network.domain_list'), url('^domains/$', DomainList.as_view(), name='network.domain_list'),
url('^domains/(?P<pk>\d+)/$', DomainDetail.as_view(), url('^domains/(?P<pk>\d+)/$', DomainDetail.as_view(),
name='network.domain'), name='network.domain'),
url('^domains/delete/(?P<pk>\d+)/$', DomainDelete.as_view(),
name="network.domain_delete"),
url('^groups/$', GroupList.as_view(), name='network.group_list'), url('^groups/$', GroupList.as_view(), name='network.group_list'),
url('^groups/(?P<pk>\d+)/$', GroupDetail.as_view(), name='network.group'), url('^groups/(?P<pk>\d+)/$', GroupDetail.as_view(), name='network.group'),
url('^groups/delete/(?P<pk>\d+)/$', GroupDelete.as_view(),
name="network.group_delete"),
url('^hosts/$', HostList.as_view(), name='network.host_list'), url('^hosts/$', HostList.as_view(), name='network.host_list'),
url('^hosts/create$', HostCreate.as_view(), name='network.host_create'), url('^hosts/create$', HostCreate.as_view(), name='network.host_create'),
url('^hosts/(?P<pk>\d+)/$', HostDetail.as_view(), name='network.host'), url('^hosts/(?P<pk>\d+)/$', HostDetail.as_view(), name='network.host'),
url('^hosts/delete/(?P<pk>\d+)/$', HostDelete.as_view(),
name="network.host_delete"),
url('^records/$', RecordList.as_view(), name='network.record_list'), url('^records/$', RecordList.as_view(), name='network.record_list'),
url('^records/create$', RecordCreate.as_view(), url('^records/create$', RecordCreate.as_view(),
name='network.record_create'), name='network.record_create'),
url('^records/(?P<pk>\d+)/$', RecordDetail.as_view(), url('^records/(?P<pk>\d+)/$', RecordDetail.as_view(),
name='network.record'), name='network.record'),
url('^records/delete/(?P<pk>\d+)/$', RecordDelete.as_view(),
name="network.record_delete"),
url('^rules/$', RuleList.as_view(), name='network.rule_list'), url('^rules/$', RuleList.as_view(), name='network.rule_list'),
url('^rules/(?P<pk>\d+)/$', RuleDetail.as_view(), url('^rules/(?P<pk>\d+)/$', RuleDetail.as_view(),
name='network.rule'), name='network.rule'),
url('^vlans/$', VlanList.as_view(), name='network.vlan_list'), url('^vlans/$', VlanList.as_view(), name='network.vlan_list'),
url('^vlans/(?P<vid>\d+)/$', VlanDetail.as_view(), name='network.vlan'), url('^vlans/(?P<vid>\d+)/$', VlanDetail.as_view(), name='network.vlan'),
url('^vlans/delete/(?P<vid>\d+)/$', VlanDelete.as_view(),
name="network.vlan_delete"),
url('^vlangroups/$', VlanGroupList.as_view(), url('^vlangroups/$', VlanGroupList.as_view(),
name='network.vlan_group_list'), name='network.vlan_group_list'),
url('^vlangroups/(?P<pk>\d+)/$', VlanGroupDetail.as_view(), url('^vlangroups/(?P<pk>\d+)/$', VlanGroupDetail.as_view(),
name='network.vlan_group'), name='network.vlan_group'),
url('^vlangroups/delete/(?P<pk>\d+)/$', VlanGroupDelete.as_view(),
name="network.vlangroup_delete"),
url('^rules/delete/(?P<pk>\d+)/$', RuleDelete.as_view(), url('^rules/delete/(?P<pk>\d+)/$', RuleDelete.as_view(),
name="network.rule_delete"), name="network.rule_delete"),
url('^hosts/(?P<pk>\d+)/remove/(?P<group_pk>\d+)/$', remove_host_group, url('^hosts/(?P<pk>\d+)/remove/(?P<group_pk>\d+)/$', remove_host_group,
......
...@@ -14,6 +14,8 @@ from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable, ...@@ -14,6 +14,8 @@ from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable,
from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm, from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
BlacklistForm, RuleForm, VlanGroupForm) BlacklistForm, RuleForm, VlanGroupForm)
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from itertools import chain from itertools import chain
import json import json
...@@ -66,6 +68,33 @@ class BlacklistDetail(UpdateView): ...@@ -66,6 +68,33 @@ class BlacklistDetail(UpdateView):
if 'pk' in self.kwargs: if 'pk' in self.kwargs:
return reverse_lazy('network.blacklist', kwargs=self.kwargs) return reverse_lazy('network.blacklist', kwargs=self.kwargs)
def get_context_data(self, **kwargs):
context = super(BlacklistDetail, self).get_context_data(**kwargs)
context['blacklist_pk'] = self.object.pk
return context
class BlacklistDelete(DeleteView):
model = Blacklist
template_name = "network/confirm/base_delete.html"
def get_context_data(self, **kwargs):
""" display more information about the object """
context = super(BlacklistDelete, self).get_context_data(**kwargs)
if 'pk' in self.kwargs:
to_delete = Blacklist.objects.get(pk=self.kwargs['pk'])
context['to_delete'] = "%s - %s - %s" % (to_delete.ipv4,
to_delete.reason,
to_delete.type)
return context
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return self.request.POST['next']
else:
return reverse_lazy('network.blacklist_list')
class DomainList(SingleTableView): class DomainList(SingleTableView):
model = Domain model = Domain
...@@ -83,6 +112,23 @@ class DomainDetail(UpdateView): ...@@ -83,6 +112,23 @@ class DomainDetail(UpdateView):
if 'pk' in self.kwargs: if 'pk' in self.kwargs:
return reverse_lazy('network.domain', kwargs=self.kwargs) return reverse_lazy('network.domain', kwargs=self.kwargs)
def get_context_data(self, *args, **kwargs):
context = super(DomainDetail, self).get_context_data(**kwargs)
context['domain_pk'] = self.get_object().pk
return context
class DomainDelete(DeleteView):
model = Domain
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return self.request.POST['next']
else:
return reverse_lazy('network.domain_list')
class GroupList(SingleTableView): class GroupList(SingleTableView):
model = Group model = Group
...@@ -101,6 +147,23 @@ class GroupDetail(UpdateView): ...@@ -101,6 +147,23 @@ class GroupDetail(UpdateView):
return reverse_lazy('network.group', kwargs=self.kwargs) return reverse_lazy('network.group', kwargs=self.kwargs)
class GroupDelete(DeleteView):
model = Group
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return self.request.POST['next']
else:
return reverse_lazy('network.group_list')
def get_context_data(self, *args, **kwargs):
context = super(GroupDelete, self).get_context_data(**kwargs)
context['group_pk'] = self.object.pk
return context
class HostList(SingleTableView): class HostList(SingleTableView):
model = Host model = Host
table_class = HostTable table_class = HostTable
...@@ -192,6 +255,43 @@ class HostCreate(CreateView): ...@@ -192,6 +255,43 @@ class HostCreate(CreateView):
form_class = HostForm form_class = HostForm
class HostDelete(DeleteView):
model = Host
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return self.request.POST['next']
else:
return reverse_lazy('network.host_list')
def get_context_data(self, *args, **kwargs):
context = super(HostDelete, self).get_context_data(**kwargs)
deps = []
records = Record.objects.filter(host=self.object).all()
if records:
deps.append({
'name': 'Records',
'data': records
})
context['deps'] = deps
context['confirmation'] = True
return context
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(HostDelete, self).delete(request, *args, **kwargs)
messages.success(request, "Deletion successful!")
return response
class RecordList(SingleTableView): class RecordList(SingleTableView):
model = Record model = Record
table_class = RecordTable table_class = RecordTable
...@@ -206,8 +306,8 @@ class RecordDetail(UpdateView): ...@@ -206,8 +306,8 @@ class RecordDetail(UpdateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(RecordDetail, self).get_context_data(**kwargs) context = super(RecordDetail, self).get_context_data(**kwargs)
q = Record.objects.get(pk=self.object.pk).fqdn context['fqdn'] = self.object.fqdn
context['fqdn'] = q context['record_pk'] = self.object.pk
return context return context
def get_success_url(self): def get_success_url(self):
...@@ -221,6 +321,18 @@ class RecordCreate(CreateView): ...@@ -221,6 +321,18 @@ class RecordCreate(CreateView):
form_class = RecordForm form_class = RecordForm
class RecordDelete(DeleteView):
model = Record
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return self.request.POST['next']
else:
return reverse_lazy('network.record_list')
class RuleList(SingleTableView): class RuleList(SingleTableView):
model = Rule model = Rule
table_class = RuleTable table_class = RuleTable
...@@ -240,8 +352,7 @@ class RuleDetail(UpdateView): ...@@ -240,8 +352,7 @@ class RuleDetail(UpdateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(RuleDetail, self).get_context_data(**kwargs) context = super(RuleDetail, self).get_context_data(**kwargs)
pk = self.kwargs.get('pk') rule = self.get_object()
rule = Rule.objects.get(pk=pk)
context['rule'] = rule context['rule'] = rule
return context return context
...@@ -249,11 +360,12 @@ class RuleDetail(UpdateView): ...@@ -249,11 +360,12 @@ class RuleDetail(UpdateView):
class RuleDelete(DeleteView): class RuleDelete(DeleteView):
model = Rule model = Rule
template_name = "network/confirm/rule_delete.html" template_name = "network/confirm/base_delete.html"
def get_success_url(self): def get_success_url(self):
if 'next' in self.request.POST: next = self.request.POST.get('next')
return self.request.POST['next'] if next:
return next
else: else:
return reverse_lazy('network.rule_list') return reverse_lazy('network.rule_list')
...@@ -276,11 +388,62 @@ class VlanDetail(UpdateView): ...@@ -276,11 +388,62 @@ class VlanDetail(UpdateView):
context = super(VlanDetail, self).get_context_data(**kwargs) context = super(VlanDetail, self).get_context_data(**kwargs)
q = Host.objects.filter(vlan=self.object).all() q = Host.objects.filter(vlan=self.object).all()
context['host_list'] = SmallHostTable(q) context['host_list'] = SmallHostTable(q)
context['vlan_vid'] = self.kwargs.get('vid')
return context return context
success_url = reverse_lazy('network.vlan_list') success_url = reverse_lazy('network.vlan_list')
class VlanDelete(DeleteView):
model = Vlan
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return next
else:
return reverse_lazy('network.vlan_list')
def get_object(self, queryset=None):
""" we identify vlans by vid and not pk """
return Vlan.objects.get(vid=self.kwargs['vid'])
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(VlanDelete, self).delete(request, *args, **kwargs)
messages.success(request, "Deletion successful!")
return response
def get_context_data(self, **kwargs):
context = super(VlanDelete, self).get_context_data(**kwargs)
deps = []
# hosts
hosts = Host.objects.filter(vlan=self.get_object).all()
if len(hosts) > 0:
deps.append({
'name': 'Hosts',
'data': hosts
})
# records
records = Record.objects.filter(host__in=deps[0]['data'])
if len(records) > 0:
deps.append({
'name': 'Records',
'data': records
})
context['deps'] = deps
context['confirmation'] = True
return context
class VlanGroupList(SingleTableView): class VlanGroupList(SingleTableView):
model = VlanGroup model = VlanGroup
table_class = VlanGroupTable table_class = VlanGroupTable
...@@ -295,6 +458,23 @@ class VlanGroupDetail(UpdateView): ...@@ -295,6 +458,23 @@ class VlanGroupDetail(UpdateView):
success_url = reverse_lazy('network.vlan_group_list') success_url = reverse_lazy('network.vlan_group_list')
def get_context_data(self, *args, **kwargs):
context = super(VlanGroupDetail, self).get_context_data(**kwargs)
context['vlangroup_pk'] = self.object.pk
return context
class VlanGroupDelete(DeleteView):
model = VlanGroup
template_name = "network/confirm/base_delete.html"
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return next
else:
return reverse_lazy('network.vlan_group_list')
def remove_host_group(request, **kwargs): def remove_host_group(request, **kwargs):
host = Host.objects.get(pk=kwargs['pk']) host = Host.objects.get(pk=kwargs['pk'])
...@@ -323,7 +503,3 @@ def add_host_group(request, **kwargs): ...@@ -323,7 +503,3 @@ def add_host_group(request, **kwargs):
group = Group.objects.get(pk=group_pk) group = Group.objects.get(pk=group_pk)
host.groups.add(group) host.groups.add(group)
return redirect(reverse_lazy('network.host', kwargs=kwargs)) return redirect(reverse_lazy('network.host', kwargs=kwargs))
def get_host_as_json(request, **kwargs):
pass
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