Commit 73e373a6 authored by chirac's avatar chirac

Erreurs avec need_infra

parent 27e5180e
......@@ -51,12 +51,12 @@ class BaseEditInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
fields = ['ipv4','mac_address','dns','type','details']
def __init__(self, infra=False, *args, **kwargs):
def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra')
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
if not infra:
self.fields['type'].queryset = MachineType.objects.filter(IpType.objects.filter(need_infra=False))
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
class MachineTypeForm(ModelForm):
......@@ -43,7 +43,7 @@ class Interface(models.Model):
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
details = models.CharField(max_length=255, blank=True)
dns = models.CharField(help_text="Obligatoire et unique, doit se terminer par exemple en %s et ne pas comporter d'autres points" % MAIN_EXTENSION, max_length=255, unique=True)
dns = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255, unique=True)
def is_active(self):
""" Renvoie si une interface doit avoir accès ou non """
......@@ -29,17 +29,11 @@ def full_domain_validator(request, interface):
""" Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """
HOSTNAME_LABEL_PATTERN = re.compile("(?!-)[A-Z\d-]+(?<!-)$", re.IGNORECASE)
dns = interface.dns.lower()
allowed_extension =
if not dns.endswith(allowed_extension):
"Le nom de domaine %s doit comporter une extension valide en %s" % (dns, allowed_extension) )
return False
dns_short=re.sub('%s$' % allowed_extension, '', dns)
if len(dns_short) > 63:
if len(dns) > 63:
"Le nom de domaine %s est trop long (maximum de 63 caractères)." % dns)
return False
if not HOSTNAME_LABEL_PATTERN.match(dns_short):
if not HOSTNAME_LABEL_PATTERN.match(dns):
"Ce nom de domaine %s contient des carractères interdits." % dns)
return False
......@@ -133,7 +127,7 @@ def edit_interface(request, interfaceid):
interface_form = BaseEditInterfaceForm(request.POST or None, instance=interface, infra=False)
machine_form = EditMachineForm(request.POST or None, instance=interface.machine)
interface_form = EditInterfaceForm(request.POST or None, instance=interface, infra=True)
interface_form = EditInterfaceForm(request.POST or None, instance=interface)
if machine_form.is_valid() and interface_form.is_valid():
new_interface =
new_machine =
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