Commit 91d35ea6 by Őry Máté

network: add vlan views

parent edf54253
...@@ -5,7 +5,7 @@ from crispy_forms.helper import FormHelper ...@@ -5,7 +5,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Row, HTML from crispy_forms.layout import Layout, Fieldset, Row, HTML
from crispy_forms.layout import Div, ButtonHolder, Submit, BaseInput from crispy_forms.layout import Div, ButtonHolder, Submit, BaseInput
from firewall.models import Host from firewall.models import Host, Vlan
class LinkButton(BaseInput): class LinkButton(BaseInput):
...@@ -68,3 +68,58 @@ class HostForm(ModelForm): ...@@ -68,3 +68,58 @@ class HostForm(ModelForm):
class Meta: class Meta:
model = Host model = Host
class VlanForm(ModelForm):
helper = FormHelper()
helper.layout = Layout(
Div(
Row(
Div(
Fieldset(
'Identity',
'name',
'vid',
'interface',
),
Fieldset(
'IPv4',
'net4',
'prefix4',
'ipv4',
'snat_to',
'snat_ip',
'dhcp_pool',
),
Fieldset(
'IPv6',
'net6',
'prefix6',
'ipv6',
),
Fieldset(
'Domain name service',
'domain',
'reverse_domain',
),
Fieldset(
'Info',
'description',
'comment',
# 'created_at',
# 'modified_at',
),
css_class='span8'),
Div(
HTML('<p>hello</p>'),
css_class='span4'),
),
ButtonHolder(
Submit('submit', 'Save'),
LinkButton('back', 'Back', reverse_lazy(
'network.host_list'))
),
css_class="form-horizontal"))
class Meta:
model = Vlan
from django_tables2 import Table, A from django_tables2 import Table, A
from django_tables2.columns import LinkColumn from django_tables2.columns import LinkColumn
from firewall.models import Host from firewall.models import Host, Vlan
class HostTable(Table): class HostTable(Table):
hostname = LinkColumn('network.host', args=[A('pk')]) hostname = LinkColumn('network.host', args=[A('pk')])
...@@ -12,3 +13,12 @@ class HostTable(Table): ...@@ -12,3 +13,12 @@ class HostTable(Table):
fields = ('hostname', 'vlan', 'mac', 'ipv4', 'ipv6', fields = ('hostname', 'vlan', 'mac', 'ipv4', 'ipv6',
'pub_ipv4', 'created_at', 'owner', ) 'pub_ipv4', 'created_at', 'owner', )
class VlanTable(Table):
name = LinkColumn('network.vlan', args=[A('pk')])
class Meta:
model = Vlan
attrs = {'class': 'table table-striped table-condensed'}
fields = ('vid', 'name', 'interface', 'ipv4', 'ipv6', 'domain', )
order_by = 'vid'
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block content %}
<div class="page-heading">
<h1>{{ form.hostname.value }} <small>details of host</small></h1>
</div>
{% crispy form %}
{% endblock %}
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% block content %}
<div class="page-heading">
<h1>Hosts <small>list of all hosts</small></h1>
</div>
{% render_table table %}
{% endblock %}
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from .views import IndexView, HostList, HostDetail from .views import IndexView, HostList, HostDetail, VlanList, VlanDetail
urlpatterns = patterns( urlpatterns = patterns(
...@@ -8,4 +8,6 @@ urlpatterns = patterns( ...@@ -8,4 +8,6 @@ urlpatterns = patterns(
url('^$', IndexView.as_view(), name='network.index'), url('^$', IndexView.as_view(), name='network.index'),
url('^hosts/$', HostList.as_view(), name='network.host_list'), url('^hosts/$', HostList.as_view(), name='network.host_list'),
url('^hosts/(?P<pk>\d+)/$', HostDetail.as_view(), name='network.host'), url('^hosts/(?P<pk>\d+)/$', HostDetail.as_view(), name='network.host'),
url('^vlans/$', VlanList.as_view(), name='network.vlan_list'),
url('^vlans/(?P<pk>\d+)/$', VlanDetail.as_view(), name='network.vlan'),
) )
...@@ -3,9 +3,9 @@ from django.views.generic import UpdateView ...@@ -3,9 +3,9 @@ from django.views.generic import UpdateView
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from firewall.models import Host from firewall.models import Host, Vlan
from .tables import HostTable from .tables import HostTable, VlanTable
from .forms import HostForm from .forms import HostForm, VlanForm
class IndexView(TemplateView): class IndexView(TemplateView):
...@@ -22,3 +22,15 @@ class HostDetail(UpdateView): ...@@ -22,3 +22,15 @@ class HostDetail(UpdateView):
model = Host model = Host
template_name = "network/host-edit.html" template_name = "network/host-edit.html"
form_class = HostForm form_class = HostForm
class VlanList(SingleTableView):
model = Vlan
table_class = VlanTable
template_name = "network/vlan-list.html"
class VlanDetail(UpdateView):
model = Vlan
template_name = "network/vlan-edit.html"
form_class = VlanForm
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