From 7ad79a11c397e2276dcdf56ed11ab20a757e1583 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 18 Jul 2016 13:48:58 +0200 Subject: [PATCH] Simplifie code moche --- machines/templates/machines/machine.html | 4 ++++ machines/views.py | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/machines/templates/machines/machine.html b/machines/templates/machines/machine.html index 420a37c2..a8d287f6 100644 --- a/machines/templates/machines/machine.html +++ b/machines/templates/machines/machine.html @@ -4,14 +4,18 @@ {% block title %}Création et modification de machines{% endblock %} {% block content %} +{% if machineform %} {% bootstrap_form_errors machineform %} +{% endif %} {% if interfaceform %} {% bootstrap_form_errors interfaceform %} {% endif %}
{% csrf_token %} + {% if machineform %} {% bootstrap_form machineform %} + {% endif %} {% if interfaceform %} {% bootstrap_form interfaceform %} {% endif %} diff --git a/machines/views.py b/machines/views.py index eec189c8..a8989a46 100644 --- a/machines/views.py +++ b/machines/views.py @@ -150,12 +150,8 @@ def new_interface(request, machineid): if machine.user != request.user: messages.error(request, "Vous ne pouvez pas ajouter une interface à une machine d'un autre user que vous sans droit") return redirect("/users/profil/" + str(request.user.id)) - machine_form = BaseEditMachineForm(request.POST or None, instance=machine) - else: - machine_form = EditMachineForm(request.POST or None, instance=machine) interface_form = AddInterfaceForm(request.POST or None) - if interface_form.is_valid() and machine_form.is_valid(): - machine_form.save() + if interface_form.is_valid(): new_interface = interface_form.save(commit=False) new_interface.machine = machine if full_domain_validator(request, new_interface, machine): @@ -166,7 +162,7 @@ def new_interface(request, machineid): new_interface.save() messages.success(request, "L'interface a été ajoutée") return redirect("/machines/") - return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request) + return form({'interfaceform': interface_form}, 'machines/machine.html', request) @login_required def del_interface(request, interfaceid):