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
Conflicts: machines/views.py
This commit is contained in:
parent
3ce3c757b9
commit
dbbbee5fc7
2 changed files with 91 additions and 0 deletions
|
@ -31,6 +31,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']
|
||||
|
|
|
@ -101,6 +101,7 @@ def new_machine(request, userid):
|
|||
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
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)
|
||||
<<<<<<< HEAD
|
||||
if machine.is_valid() and interface.is_valid():
|
||||
new_machine = machine.save(commit=False)
|
||||
new_machine.user = user
|
||||
|
@ -127,6 +128,37 @@ def new_machine(request, userid):
|
|||
reversion.set_comment("Création")
|
||||
messages.success(request, "La machine a été crée")
|
||||
return redirect("/users/profil/" + userid)
|
||||
=======
|
||||
try:
|
||||
if machine.is_valid() and interface.is_valid() and domain.is_valid():
|
||||
new_machine = machine.save(commit=False)
|
||||
new_machine.user = user
|
||||
new_interface = interface.save(commit=False)
|
||||
new_domain = domain.save(commit=False)
|
||||
if full_domain_validator(request, new_domain):
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_machine.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
new_interface.machine = new_machine
|
||||
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
|
||||
new_interface = assign_ipv4(new_interface)
|
||||
elif not new_interface.ipv4:
|
||||
messages.error(request, u"Il n'y a plus d'ip disponibles")
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_interface.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
new_domain.interface_parent = new_interface
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_domain.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "La machine a été crée")
|
||||
return redirect("/users/profil/" + str(user.id))
|
||||
except TypeError:
|
||||
messages.error(request, u"Adresse mac invalide")
|
||||
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
|
||||
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
|
@ -146,6 +178,7 @@ def edit_interface(request, interfaceid):
|
|||
machine_form = EditMachineForm(request.POST or None, instance=interface.machine)
|
||||
interface_form = EditInterfaceForm(request.POST or None, instance=interface)
|
||||
domain_form = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)), instance=interface.domain)
|
||||
<<<<<<< HEAD
|
||||
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)
|
||||
|
@ -167,6 +200,32 @@ def edit_interface(request, interfaceid):
|
|||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data))
|
||||
messages.success(request, "La machine a été modifiée")
|
||||
return redirect("/users/profil/" + str(interface.machine.user.id))
|
||||
=======
|
||||
try:
|
||||
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)
|
||||
new_domain = domain_form.save(commit=False)
|
||||
if full_domain_validator(request, new_domain):
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_machine.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data))
|
||||
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
|
||||
new_interface = assign_ipv4(new_interface)
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_interface.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in interface_form.changed_data))
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_domain.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data))
|
||||
messages.success(request, "La machine a été modifiée")
|
||||
return redirect("/users/profil/" + str(interface.machine.user.id))
|
||||
except TypeError:
|
||||
messages.error(request, u"Adresse mac invalide")
|
||||
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
|
||||
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
|
@ -204,6 +263,7 @@ def new_interface(request, machineid):
|
|||
return redirect("/users/profil/" + str(request.user.id))
|
||||
interface_form = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
domain_form = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
<<<<<<< HEAD
|
||||
if interface_form.is_valid():
|
||||
new_interface = interface_form.save(commit=False)
|
||||
new_interface.machine = machine
|
||||
|
@ -224,6 +284,31 @@ def new_interface(request, machineid):
|
|||
reversion.set_comment("Création")
|
||||
messages.success(request, "L'interface a été ajoutée")
|
||||
return redirect("/users/profil/" + str(machine.user.id))
|
||||
=======
|
||||
try:
|
||||
if interface_form.is_valid() and domain_form.is_valid():
|
||||
new_interface = interface_form.save(commit=False)
|
||||
new_interface.machine = machine
|
||||
new_domain = domain_form.save(commit=False)
|
||||
if full_domain_validator(request, new_domain):
|
||||
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
|
||||
new_interface = assign_ipv4(new_interface)
|
||||
elif not new_interface.ipv4:
|
||||
messages.error(request, u"Il n'y a plus d'ip disponibles")
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_interface.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
new_domain.interface_parent = new_interface
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
new_domain.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "L'interface a été ajoutée")
|
||||
return redirect("/users/profil/" + str(machine.user.id))
|
||||
except TypeError:
|
||||
messages.error(request, u"Adresse mac invalide")
|
||||
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
|
||||
return form({'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue