Commit 40525ecc authored by chirac's avatar chirac

Menu edition complet d'un switch

parent 90071855
{% 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 %}
<form class="form" method="post">
{% 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" %}
</form>
<br />
<br />
<br />
{% endblock %}
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment