From e9190333cbc9ee91e75e693161c8e636bc3ae846 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 28 Oct 2016 02:09:24 +0200 Subject: [PATCH] Menu edition complet d'un switch --- topologie/templates/topologie/switch.html | 34 +++++++++++++++++++++++ topologie/views.py | 32 +++++++++++++++------ 2 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 topologie/templates/topologie/switch.html diff --git a/topologie/templates/topologie/switch.html b/topologie/templates/topologie/switch.html new file mode 100644 index 00000000..56ace43d --- /dev/null +++ b/topologie/templates/topologie/switch.html @@ -0,0 +1,34 @@ +{% extends "topologie/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Création et modification d'un switch{% endblock %} + +{% block content %} +{% if topoform %} +{% bootstrap_form_errors topoform %} +{% endif %} +{% if machineform %} +{% bootstrap_form_errors machineform %} +{% endif %} +{% if interfaceform %} +{% bootstrap_form_errors interfaceform %} +{% endif %} + + +
+ {% csrf_token %} + {% if topoform %} + {% bootstrap_form topoform %} + {% endif %} + {% if machineform %} + {% bootstrap_form machineform %} + {% endif %} + {% if interfaceform %} + {% bootstrap_form interfaceform %} + {% endif %} + {% bootstrap_button "Créer ou modifier" button_type="submit" icon="ok" %} +
+
+
+
+{% endblock %} diff --git a/topologie/views.py b/topologie/views.py index 27897414..6f2ec787 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -164,15 +164,29 @@ def edit_switch(request, switch_id): except Switch.DoesNotExist: messages.error(request, u"Switch inexistant") return redirect("/topologie/") - switch = EditSwitchForm(request.POST or None, instance=switch) - if switch.is_valid(): - with transaction.atomic(), reversion.create_revision(): - switch.save() - reversion.set_user(request.user) - reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in switch.changed_data)) - messages.success(request, "Le switch a bien été modifié") - return redirect("/topologie/") - return form({'topoform':switch}, 'topologie/topo.html', request) + switch_form = EditSwitchForm(request.POST or None, instance=switch) + machine_form = EditMachineForm(request.POST or None, instance=switch.switch_interface.machine) + interface_form = EditInterfaceForm(request.POST or None, instance=switch.switch_interface) + if switch_form.is_valid() and machine_form.is_valid() and interface_form.is_valid(): + new_interface = interface_form.save(commit=False) + new_machine = machine_form.save(commit=False) + new_switch = switch_form.save(commit=False) + if full_domain_validator(request, new_interface): + 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)) + 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_switch.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in switch_form.changed_data)) + messages.success(request, "Le switch a bien été modifié") + return redirect("/topologie/") + return form({'topoform':switch_form, 'machineform': machine_form, 'interfaceform': interface_form}, 'topologie/switch.html', request) @login_required @permission_required('infra')