Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit c33a0b9b authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

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

parent e21b3935
# -*- 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)
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)
......
......@@ -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)
......
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 to comment