8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Mise en conformité

This commit is contained in:
Gabriel Detraz 2017-01-16 02:05:56 +01:00 committed by root
parent 30456162ca
commit 253202520b

View file

@ -123,55 +123,10 @@ 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
<<<<<<< HEAD
if machine.is_valid() and interface.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")
<<<<<<< HEAD
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
<<<<<<< HEAD
=======
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)
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
=======
try:
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 trop courte")
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
>>>>>>> 9be0510... Normalement ca gere les bugs d'ajout et verifie la validité du domaine
new_interface = interface.save(commit=False)
new_domain = domain.save(commit=False)
if full_domain_validator(request, new_domain):
@ -197,13 +152,6 @@ def new_machine(request, userid):
return redirect("/users/profil/" + str(user.id))
except TypeError:
messages.error(request, u"Adresse mac invalide")
<<<<<<< HEAD
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
=======
return redirect("/users/profil/" + user)
>>>>>>> 9b69205... Retour sur le profil de l'utilisateur apres suppression machine
=======
>>>>>>> 9be0510... Normalement ca gere les bugs d'ajout et verifie la validité du domaine
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'machines/machine.html', request)
@login_required
@ -223,42 +171,10 @@ 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
<<<<<<< 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)
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))
=======
=======
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
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)
<<<<<<< HEAD
=======
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)
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain):
with transaction.atomic(), reversion.create_revision():
@ -279,10 +195,6 @@ def edit_interface(request, interfaceid):
return redirect("/users/profil/" + str(interface.machine.user.id))
except TypeError:
messages.error(request, u"Adresse mac invalide")
<<<<<<< HEAD
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
=======
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
@login_required
@ -320,40 +232,9 @@ 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
<<<<<<< HEAD
if interface_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))
=======
try:
if interface_form.is_valid() and domain_form.is_valid():
new_interface = interface_form.save(commit=False)
=======
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)
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
new_interface.machine = machine
new_domain = domain_form.save(commit=False)
if full_domain_validator(request, new_domain):
@ -374,10 +255,6 @@ def new_interface(request, machineid):
return redirect("/users/profil/" + str(machine.user.id))
except TypeError:
messages.error(request, u"Adresse mac invalide")
<<<<<<< HEAD
>>>>>>> b660cf0... Prise en compte des erreurs sur la mac
=======
>>>>>>> 5a7c1b3... Gestion de l'erreur sur les autres fctions
return form({'interfaceform': interface_form, 'domainform': domain_form}, 'machines/machine.html', request)
@login_required
@ -861,7 +738,7 @@ def interface_list(request):
@login_required
@permission_required('serveur')
def alias(request):
alias = Domain.objects.filter(interface_parent=None).filter(cname__in=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None)))
alias = Domain.objects.filter(interface_parent=None).filter(cname=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None)))
seria = DomainSerializer(alias, many=True)
return JSONResponse(seria.data)