Commit 435f4556 by Őry Máté

network: add magic button to ipv6_template

parent 7afb202a
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # 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.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -254,7 +254,8 @@ class VlanForm(ModelForm): ...@@ -254,7 +254,8 @@ class VlanForm(ModelForm):
Fieldset( Fieldset(
_('IPv6'), _('IPv6'),
'network6', 'network6',
'ipv6_template', FieldWithButtons('ipv6_template', StrictButton(
'<i class="fa fa-magic"></i>', css_id="ipv6-tpl-magic")),
'host_ipv6_prefixlen', 'host_ipv6_prefixlen',
), ),
Fieldset( Fieldset(
...@@ -279,6 +280,9 @@ class VlanForm(ModelForm): ...@@ -279,6 +280,9 @@ class VlanForm(ModelForm):
class Meta: class Meta:
model = Vlan model = Vlan
widgets = {
'ipv6_template': widgets.TextInput,
}
class VlanGroupForm(ModelForm): class VlanGroupForm(ModelForm):
......
...@@ -49,4 +49,12 @@ $("#ipv4-magic").click(function() { ...@@ -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 @@ ...@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from netaddr import IPNetwork
from django.views.generic import (TemplateView, UpdateView, DeleteView, from django.views.generic import (TemplateView, UpdateView, DeleteView,
CreateView) CreateView)
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -701,7 +702,27 @@ class VlanAclUpdateView(AclUpdateView): ...@@ -701,7 +702,27 @@ class VlanAclUpdateView(AclUpdateView):
model = Vlan 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): SuccessMessageMixin, UpdateView):
model = Vlan model = Vlan
template_name = "network/vlan-edit.html" template_name = "network/vlan-edit.html"
...@@ -723,7 +744,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -723,7 +744,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
success_url = reverse_lazy('network.vlan_list') success_url = reverse_lazy('network.vlan_list')
class VlanCreate(LoginRequiredMixin, SuperuserRequiredMixin, class VlanCreate(VlanMagicMixin, LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, InitialOwnerMixin, CreateView): SuccessMessageMixin, InitialOwnerMixin, CreateView):
model = Vlan model = Vlan
template_name = "network/vlan-create.html" 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