8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 16:42:25 +00:00

Normalement ca gere les bugs d'ajout et verifie la validité du domaine

This commit is contained in:
Dalahro 2017-01-13 22:25:03 +01:00
parent 9b69205982
commit 9be0510f00
2 changed files with 34 additions and 27 deletions

View file

@ -69,7 +69,8 @@ class AliasForm(ModelForm):
fields = ['name','extension'] fields = ['name','extension']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra') if 'infra' in kwargs:
infra = kwargs.pop('infra')
if 'name_user' in kwargs: if 'name_user' in kwargs:
name_user = kwargs.pop('name_user') name_user = kwargs.pop('name_user')
nb_machine = kwargs.pop('nb_machine') nb_machine = kwargs.pop('nb_machine')

View file

@ -101,32 +101,38 @@ def new_machine(request, userid):
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',))) interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
nb_machine = Interface.objects.filter(machine__user=userid).count() 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) domain = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)), name_user=user.surname, nb_machine=nb_machine)
if machine.is_valid() and interface.is_valid(): try:
new_machine = machine.save(commit=False) if machine.is_valid() and interface.is_valid() and domain.is_valid():
new_machine.user = user new_machine = machine.save(commit=False)
new_interface = interface.save(commit=False) new_machine.user = user
new_domain = domain.save(commit=False) if len(interface.cleaned_data['mac_address']) != 12:
if full_domain_validator(request, new_domain): messages.error(request, u"Adresse mac trop courte")
with transaction.atomic(), reversion.create_revision(): return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
new_machine.save() new_interface = interface.save(commit=False)
reversion.set_user(request.user) new_domain = domain.save(commit=False)
reversion.set_comment("Création") if full_domain_validator(request, new_domain):
new_interface.machine = new_machine with transaction.atomic(), reversion.create_revision():
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4: new_machine.save()
new_interface = assign_ipv4(new_interface) reversion.set_user(request.user)
elif not new_interface.ipv4: reversion.set_comment("Création")
messages.error(request, u"Il n'y a plus d'ip disponibles") new_interface.machine = new_machine
with transaction.atomic(), reversion.create_revision(): if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
new_interface.save() new_interface = assign_ipv4(new_interface)
reversion.set_user(request.user) elif not new_interface.ipv4:
reversion.set_comment("Création") messages.error(request, u"Il n'y a plus d'ip disponibles")
new_domain.interface_parent = new_interface with transaction.atomic(), reversion.create_revision():
with transaction.atomic(), reversion.create_revision(): new_interface.save()
new_domain.save() reversion.set_user(request.user)
reversion.set_user(request.user) reversion.set_comment("Création")
reversion.set_comment("Création") new_domain.interface_parent = new_interface
messages.success(request, "La machine a été crée") with transaction.atomic(), reversion.create_revision():
return redirect("/users/profil/" + user) 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")
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request) return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
@login_required @login_required