8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-21 19:03:11 +00:00

Prise en compte des erreurs sur la mac

This commit is contained in:
Dalahro 2017-01-14 15:46:21 +01:00
parent 68a593cbb7
commit b660cf0343
2 changed files with 7 additions and 10 deletions

View file

@ -32,6 +32,12 @@ class EditInterfaceForm(ModelForm):
self.fields['type'].label = 'Type de machine'
self.fields['type'].empty_label = "Séléctionner un type de machine"
def clean(self):
data = super(EditInterfaceForm, self).clean()
mac = str(self.data['mac_address'])
if len(''.join(mac.replace("-",":").split(":"))) != 12:
self.add_error('mac_address', "Format de la mac incorrect")
class AddInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
fields = ['ipv4','mac_address','type','details']

View file

@ -102,12 +102,9 @@ def new_machine(request, userid):
nb_machine = Interface.objects.filter(machine__user=userid).count()
domain = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)), name_user=user.surname, nb_machine=nb_machine)
try:
if machine.is_valid() and interface.is_valid() and domain.is_valid():
if machine.is_valid() and interface.is_valid() and domain.is_valid():
new_machine = machine.save(commit=False)
new_machine.user = user
if len(interface.cleaned_data['mac_address']) != 12:
messages.error(request, u"Adresse mac de taille incorrecte")
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
new_interface = interface.save(commit=False)
new_domain = domain.save(commit=False)
if full_domain_validator(request, new_domain):
@ -156,9 +153,6 @@ def edit_interface(request, interfaceid):
if machine_form.is_valid() and interface_form.is_valid() and domain_form.is_valid():
new_interface = interface_form.save(commit=False)
new_machine = machine_form.save(commit=False)
if len(interface_form.cleaned_data['mac_address']) != 12:
messages.error(request, u"Adresse mac de taille incorrecte")
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain):
with transaction.atomic(), reversion.create_revision():
@ -219,9 +213,6 @@ def new_interface(request, machineid):
try:
if interface_form.is_valid() and domain_form.is_valid():
new_interface = interface_form.save(commit=False)
if len(interface_form.cleaned_data['mac_address']) != 12:
messages.error(request, u"Adresse mac de taille incorrecte")
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
new_interface.machine = machine
new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain):