8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Erreurs avec need_infra

This commit is contained in:
chirac 2016-10-24 19:52:29 +02:00
parent 27e5180e23
commit 73e373a648
3 changed files with 6 additions and 12 deletions

View file

@ -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):

View file

@ -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 """

View file

@ -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 = interface.ipv4.type.extension.name
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:
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)