From be948084cfe45af01370f3dee647c92eafc53d3f Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 24 Oct 2016 19:52:29 +0200 Subject: [PATCH] Erreurs avec need_infra --- machines/forms.py | 4 ++-- machines/models.py | 2 +- machines/views.py | 12 +++--------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index 5b40f2ca..468b6140 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -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): diff --git a/machines/models.py b/machines/models.py index 5d2fa8e5..31d1a406 100644 --- a/machines/models.py +++ b/machines/models.py @@ -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 """ diff --git a/machines/views.py b/machines/views.py index 332d3563..5561c89e 100644 --- a/machines/views.py +++ b/machines/views.py @@ -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-]+(? 63: + if len(dns) > 63: messages.error(request, "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): messages.error(request, "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) else: 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 = interface_form.save(commit=False) new_machine = machine_form.save(commit=False)