8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00

Fix, nouvelle validation pour vérifier l'unicité de l'ip slaac

This commit is contained in:
Gabriel Detraz 2018-01-30 02:01:06 +00:00 committed by root
parent e21b393563
commit c33a0b9bb9
3 changed files with 31 additions and 4 deletions

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-01-29 23:52
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('machines', '0074_auto_20180129_0352'),
]
operations = [
migrations.AlterUniqueTogether(
name='ipv6list',
unique_together=set([]),
),
]

View file

@ -1395,7 +1395,6 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
slaac_ip = models.BooleanField(default=False)
class Meta:
unique_together = (("interface", "slaac_ip"),)
permissions = (
("view_ipv6list", "Peut voir un objet ipv6"),
("change_ipv6list_slaac_ip", "Peut changer la valeur slaac sur une ipv6"),
@ -1478,6 +1477,16 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
'slaac_ip' : self.can_change_slaac_ip,
}
def clean(self, *args, **kwargs):
if self.slaac_ip and Ipv6List.objects.filter(interface=self.interface, slaac_ip=True).exclude(id=self.id):
raise ValidationError("Une ip slaac est déjà enregistrée")
super(Ipv6List, self).clean(*args, **kwargs)
def save(self, *args, **kwargs):
"""Force à avoir appellé clean avant"""
self.full_clean()
super(Ipv6List, self).save(*args, **kwargs)
def __str__(self):
return str(self.ipv6)

View file

@ -375,10 +375,9 @@ def del_interface(request, interface, interfaceid):
@can_edit(Interface)
def new_ipv6list(request, interface, interfaceid):
"""Nouvelle ipv6"""
ipv6 = Ipv6ListForm(request.POST or None, user=request.user)
ipv6list_instance = Ipv6List(interface=interface)
ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user)
if ipv6.is_valid():
ipv6 = ipv6.save(commit=False)
ipv6.interface = interface
with transaction.atomic(), reversion.create_revision():
ipv6.save()
reversion.set_user(request.user)