8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 03:43:12 +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 608f30b92f
commit 59e877b528
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'].label = 'Type de machine'
self.fields['type'].empty_label = "Séléctionner un 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 AddInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta): class Meta(EditInterfaceForm.Meta):
fields = ['ipv4','mac_address','type','details'] fields = ['ipv4','mac_address','type','details']

View file

@ -105,9 +105,6 @@ def new_machine(request, userid):
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 = machine.save(commit=False)
new_machine.user = user 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_interface = interface.save(commit=False)
new_domain = domain.save(commit=False) new_domain = domain.save(commit=False)
if full_domain_validator(request, new_domain): 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(): if machine_form.is_valid() and interface_form.is_valid() and domain_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)
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) new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain): if full_domain_validator(request, new_domain):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -219,9 +213,6 @@ def new_interface(request, machineid):
try: try:
if interface_form.is_valid() and domain_form.is_valid(): if interface_form.is_valid() and domain_form.is_valid():
new_interface = interface_form.save(commit=False) 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_interface.machine = machine
new_domain = domain_form.save(commit=False) new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain): if full_domain_validator(request, new_domain):