mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Menu edition complet d'un switch
This commit is contained in:
parent
900718557a
commit
40525ecce4
2 changed files with 57 additions and 9 deletions
34
topologie/templates/topologie/switch.html
Normal file
34
topologie/templates/topologie/switch.html
Normal 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 %}
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue