Commit 8f0735c7 by Őry Máté

network: add unregistered dhcp clients table

parent ec0e901c
...@@ -122,6 +122,20 @@ class SmallHostTable(Table): ...@@ -122,6 +122,20 @@ class SmallHostTable(Table):
attrs = {'class': 'table table-striped table-condensed'} attrs = {'class': 'table table-striped table-condensed'}
fields = ('hostname', 'ipv4') fields = ('hostname', 'ipv4')
order_by = ('vlan', 'hostname', ) order_by = ('vlan', 'hostname', )
empty_text = _("No hosts.")
class SmallDhcpTable(Table):
mac = MACColumn(verbose_name=_("MAC address"))
hostname = Column(verbose_name=_("hostname"))
ip = Column(verbose_name=_("requested IP"))
register = TemplateColumn(
template_name="network/columns/host-register.html",
attrs={"th": {"style": "display: none;"}})
class Meta:
attrs = {'class': 'table table-striped table-condensed'}
empty_text = _("No hosts.")
class RecordTable(Table): class RecordTable(Table):
......
{% load i18n %}
<a href="{% url "network.host_create" %}?vlan={{ object.pk }}&amp;mac={{ record.mac }}&amp;hostname={{ record.hostname }}&amp;ipv4={{ record.ip }}"
title="{% trans "register host" %}"><i class="fa fa-plus-circle"></i></a>
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
<h3>{% trans "Host list" %}</h3> <h3>{% trans "Host list" %}</h3>
</div> </div>
{% render_table host_list %} {% render_table host_list %}
<div class="page-header">
<h3>{% trans "Unregistered hosts" %}</h3>
</div>
{% render_table dhcp_list %}
<div class="page-header"> <div class="page-header">
<h3>{% trans "Manage access" %}</h3> <h3>{% trans "Manage access" %}</h3>
</div> </div>
......
...@@ -20,7 +20,7 @@ from django.views.generic import (TemplateView, UpdateView, DeleteView, ...@@ -20,7 +20,7 @@ from django.views.generic import (TemplateView, UpdateView, DeleteView,
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
...@@ -30,7 +30,7 @@ from vm.models import Interface ...@@ -30,7 +30,7 @@ from vm.models import Interface
from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable, from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable,
GroupTable, RecordTable, BlacklistItemTable, RuleTable, GroupTable, RecordTable, BlacklistItemTable, RuleTable,
VlanGroupTable, SmallRuleTable, SmallGroupRuleTable, VlanGroupTable, SmallRuleTable, SmallGroupRuleTable,
SmallRecordTable, SwitchPortTable) SmallRecordTable, SwitchPortTable, SmallDhcpTable, )
from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm, from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
BlacklistItemForm, RuleForm, VlanGroupForm, SwitchPortForm) BlacklistItemForm, RuleForm, VlanGroupForm, SwitchPortForm)
...@@ -434,6 +434,8 @@ class HostCreate(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -434,6 +434,8 @@ class HostCreate(LoginRequiredMixin, SuperuserRequiredMixin,
if i in self.request.GET and i not in self.request.POST: if i in self.request.GET and i not in self.request.POST:
initial[i] = self.request.GET[i] initial[i] = self.request.GET[i]
if "vlan" in initial: if "vlan" in initial:
if not initial['vlan'].isnumeric():
raise Http404()
vlan = get_object_or_404(Vlan.objects, pk=initial['vlan']) vlan = get_object_or_404(Vlan.objects, pk=initial['vlan'])
try: try:
initial.update(vlan.get_new_address()) initial.update(vlan.get_new_address())
...@@ -711,6 +713,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -711,6 +713,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(VlanDetail, self).get_context_data(**kwargs) context = super(VlanDetail, self).get_context_data(**kwargs)
context['host_list'] = SmallHostTable(self.object.host_set.all()) context['host_list'] = SmallHostTable(self.object.host_set.all())
context['dhcp_list'] = SmallDhcpTable(self.object.get_dhcp_clients())
context['vlan_vid'] = self.kwargs.get('vid') context['vlan_vid'] = self.kwargs.get('vid')
context['acl'] = AclUpdateView.get_acl_data( context['acl'] = AclUpdateView.get_acl_data(
self.object, self.request.user, 'network.vlan-acl') self.object, self.request.user, 'network.vlan-acl')
......
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