mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Fix, nouvelle validation pour vérifier l'unicité de l'ip slaac
This commit is contained in:
parent
e21b393563
commit
c33a0b9bb9
3 changed files with 31 additions and 4 deletions
19
machines/migrations/0075_auto_20180130_0052.py
Normal file
19
machines/migrations/0075_auto_20180130_0052.py
Normal 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([]),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1395,7 +1395,6 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
|
||||||
slaac_ip = models.BooleanField(default=False)
|
slaac_ip = models.BooleanField(default=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (("interface", "slaac_ip"),)
|
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_ipv6list", "Peut voir un objet ipv6"),
|
("view_ipv6list", "Peut voir un objet ipv6"),
|
||||||
("change_ipv6list_slaac_ip", "Peut changer la valeur slaac sur une 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,
|
'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):
|
def __str__(self):
|
||||||
return str(self.ipv6)
|
return str(self.ipv6)
|
||||||
|
|
||||||
|
|
|
@ -375,10 +375,9 @@ def del_interface(request, interface, interfaceid):
|
||||||
@can_edit(Interface)
|
@can_edit(Interface)
|
||||||
def new_ipv6list(request, interface, interfaceid):
|
def new_ipv6list(request, interface, interfaceid):
|
||||||
"""Nouvelle ipv6"""
|
"""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():
|
if ipv6.is_valid():
|
||||||
ipv6 = ipv6.save(commit=False)
|
|
||||||
ipv6.interface = interface
|
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
ipv6.save()
|
ipv6.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
|
|
Loading…
Reference in a new issue