Commit 435f4556 by Őry Máté

network: add magic button to ipv6_template

parent 7afb202a
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.forms import ModelForm
from django.forms import ModelForm, widgets
from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _
......@@ -254,7 +254,8 @@ class VlanForm(ModelForm):
Fieldset(
_('IPv6'),
'network6',
'ipv6_template',
FieldWithButtons('ipv6_template', StrictButton(
'<i class="fa fa-magic"></i>', css_id="ipv6-tpl-magic")),
'host_ipv6_prefixlen',
),
Fieldset(
......@@ -279,6 +280,9 @@ class VlanForm(ModelForm):
class Meta:
model = Vlan
widgets = {
'ipv6_template': widgets.TextInput,
}
class VlanGroupForm(ModelForm):
......
......@@ -49,4 +49,12 @@ $("#ipv4-magic").click(function() {
}
}});
});
$("#ipv6-tpl-magic").click(function() {
$.ajax({url: window.location,
data: {network4: $("[name=network4]").val(),
network6: $("[name=network6]").val()},
success: function(data) {
$("[name=ipv6_template]").val(data["ipv6_template"]);
}});
});
});
......@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from netaddr import IPNetwork
from django.views.generic import (TemplateView, UpdateView, DeleteView,
CreateView)
from django.core.exceptions import ValidationError
......@@ -701,7 +702,27 @@ class VlanAclUpdateView(AclUpdateView):
model = Vlan
class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class VlanMagicMixin(object):
def _get_ajax(self, *args, **kwargs):
GET = self.request.GET
result = {}
if "network4" in GET and "network6" in GET:
try:
result["ipv6_template"] = Vlan._magic_ipv6_template(
IPNetwork(GET['network4']),
IPNetwork(GET['network6']))
except:
result["ipv6_template"] = ""
return JsonResponse({k: unicode(result[k] or "") for k in result})
def get(self, *args, **kwargs):
if self.request.is_ajax():
return self._get_ajax(*args, **kwargs)
else:
return super(VlanMagicMixin, self).get(*args, **kwargs)
class VlanDetail(VlanMagicMixin, LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, UpdateView):
model = Vlan
template_name = "network/vlan-edit.html"
......@@ -723,7 +744,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
success_url = reverse_lazy('network.vlan_list')
class VlanCreate(LoginRequiredMixin, SuperuserRequiredMixin,
class VlanCreate(VlanMagicMixin, LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, InitialOwnerMixin, CreateView):
model = Vlan
template_name = "network/vlan-create.html"
......
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