mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Erreurs avec need_infra
This commit is contained in:
parent
27e5180e23
commit
73e373a648
3 changed files with 6 additions and 12 deletions
|
@ -51,12 +51,12 @@ class BaseEditInterfaceForm(EditInterfaceForm):
|
||||||
class Meta(EditInterfaceForm.Meta):
|
class Meta(EditInterfaceForm.Meta):
|
||||||
fields = ['ipv4','mac_address','dns','type','details']
|
fields = ['ipv4','mac_address','dns','type','details']
|
||||||
|
|
||||||
def __init__(self, infra=False, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
infra = kwargs.pop('infra')
|
infra = kwargs.pop('infra')
|
||||||
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
|
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
if not infra:
|
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))
|
self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
||||||
|
|
||||||
class MachineTypeForm(ModelForm):
|
class MachineTypeForm(ModelForm):
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Interface(models.Model):
|
||||||
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
|
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
|
||||||
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
|
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
|
||||||
details = models.CharField(max_length=255, blank=True)
|
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):
|
def is_active(self):
|
||||||
""" Renvoie si une interface doit avoir accès ou non """
|
""" 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 """
|
""" 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)
|
HOSTNAME_LABEL_PATTERN = re.compile("(?!-)[A-Z\d-]+(?<!-)$", re.IGNORECASE)
|
||||||
dns = interface.dns.lower()
|
dns = interface.dns.lower()
|
||||||
allowed_extension = interface.ipv4.type.extension.name
|
if len(dns) > 63:
|
||||||
if not dns.endswith(allowed_extension):
|
|
||||||
messages.error(request,
|
|
||||||
"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:
|
|
||||||
messages.error(request,
|
messages.error(request,
|
||||||
"Le nom de domaine %s est trop long (maximum de 63 caractères)." % dns)
|
"Le nom de domaine %s est trop long (maximum de 63 caractères)." % dns)
|
||||||
return False
|
return False
|
||||||
if not HOSTNAME_LABEL_PATTERN.match(dns_short):
|
if not HOSTNAME_LABEL_PATTERN.match(dns):
|
||||||
messages.error(request,
|
messages.error(request,
|
||||||
"Ce nom de domaine %s contient des carractères interdits." % dns)
|
"Ce nom de domaine %s contient des carractères interdits." % dns)
|
||||||
return False
|
return False
|
||||||
|
@ -133,7 +127,7 @@ def edit_interface(request, interfaceid):
|
||||||
interface_form = BaseEditInterfaceForm(request.POST or None, instance=interface, infra=False)
|
interface_form = BaseEditInterfaceForm(request.POST or None, instance=interface, infra=False)
|
||||||
else:
|
else:
|
||||||
machine_form = EditMachineForm(request.POST or None, instance=interface.machine)
|
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():
|
if machine_form.is_valid() and interface_form.is_valid():
|
||||||
new_interface = interface_form.save(commit=False)
|
new_interface = interface_form.save(commit=False)
|
||||||
new_machine = machine_form.save(commit=False)
|
new_machine = machine_form.save(commit=False)
|
||||||
|
|
Loading…
Reference in a new issue