8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 16:33:47 +00:00

Menu edition complet d'un switch

This commit is contained in:
Gabriel Detraz 2016-10-28 02:09:24 +02:00
parent 062010cd9f
commit e9190333cb
2 changed files with 57 additions and 9 deletions

View file

@ -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 %}
<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 %}

View file

@ -164,15 +164,29 @@ def edit_switch(request, switch_id):
except Switch.DoesNotExist: except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant") messages.error(request, u"Switch inexistant")
return redirect("/topologie/") return redirect("/topologie/")
switch = EditSwitchForm(request.POST or None, instance=switch) switch_form = EditSwitchForm(request.POST or None, instance=switch)
if switch.is_valid(): 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(): with transaction.atomic(), reversion.create_revision():
switch.save() new_machine.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in switch.changed_data)) 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é") messages.success(request, "Le switch a bien été modifié")
return redirect("/topologie/") return redirect("/topologie/")
return form({'topoform':switch}, 'topologie/topo.html', request) return form({'topoform':switch_form, 'machineform': machine_form, 'interfaceform': interface_form}, 'topologie/switch.html', request)
@login_required @login_required
@permission_required('infra') @permission_required('infra')