8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00
This commit is contained in:
chirac 2016-12-24 20:20:25 +01:00
parent 5c04088a0a
commit a87f5e6605
5 changed files with 29 additions and 5 deletions

View file

@ -10,6 +10,10 @@
{% if interfaceform %}
{% bootstrap_form_errors interfaceform %}
{% endif %}
{% if domainform %}
{% bootstrap_form_errors interfaceform %}
{% endif %}
<form class="form" method="post">
{% csrf_token %}

View file

@ -138,7 +138,7 @@
</div>
<ul class="list-group">
{% for interface in interfaces|slice:":5" %}
<div class="list-group-item">{{interface.dns}}</div>
<div class="list-group-item">{{interface}}</div>
{% endfor %}
{% if interfaces|length > 5 %}
<a class="list-group-item list-group-item-info" role="button" href="{% url "users:mon-profil" %}">

View file

@ -13,7 +13,7 @@
<tr>
<td>
<a title="Configuer" href="{% url 'topologie:index-port' switch.pk %}">
{{switch.switch_interface.dns}}
{{switch.switch_interface}}
</a>
</td>
<td>{{switch.switch_interface.ipv4}}</td>

View file

@ -13,6 +13,10 @@
{% if interfaceform %}
{% bootstrap_form_errors interfaceform %}
{% endif %}
{% if domainform %}
{% bootstrap_form_errors domainform %}
{% endif %}
<form class="form" method="post">
@ -26,6 +30,9 @@
{% if interfaceform %}
{% bootstrap_form interfaceform %}
{% endif %}
{% if domainform %}
{% bootstrap_form domainform %}
{% endif %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="ok" %}
</form>
<br />

View file

@ -124,6 +124,7 @@ def new_switch(request):
switch = NewSwitchForm(request.POST or None)
machine = NewMachineForm(request.POST or None)
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
domain = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
if switch.is_valid() and machine.is_valid() and interface.is_valid():
try:
user = User.objects.get(pseudo=ASSO_PSEUDO)
@ -134,7 +135,8 @@ def new_switch(request):
new_machine.user = user
new_interface = interface.save(commit=False)
new_switch = switch.save(commit=False)
if full_domain_validator(request, new_interface):
new_domain = domain.save(commit=False)
if full_domain_validator(request, new_domain):
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
@ -148,6 +150,11 @@ def new_switch(request):
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_domain.interface_parent = new_interface
with transaction.atomic(), reversion.create_revision():
new_domain.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_switch.switch_interface = new_interface
with transaction.atomic(), reversion.create_revision():
new_switch.save()
@ -155,7 +162,7 @@ def new_switch(request):
reversion.set_comment("Création")
messages.success(request, "Le switch a été crée")
return redirect("/topologie/")
return form({'topoform':switch, 'machineform': machine, 'interfaceform': interface}, 'topologie/switch.html', request)
return form({'topoform':switch, 'machineform': machine, 'interfaceform': interface, 'domainform': domain}, 'topologie/switch.html', request)
@login_required
@permission_required('infra')
@ -168,10 +175,12 @@ def edit_switch(request, switch_id):
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)
domain_form = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)), instance=switch.switch_interface.domain)
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)
new_domain = domain.save(commit=False)
if full_domain_validator(request, new_interface):
with transaction.atomic(), reversion.create_revision():
new_machine.save()
@ -181,13 +190,17 @@ def edit_switch(request, switch_id):
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_domain.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_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)
return form({'topoform':switch_form, 'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form}, 'topologie/switch.html', request)
@login_required
@permission_required('infra')