diff --git a/cotisations/templates/cotisations/delete.html b/cotisations/templates/cotisations/delete.html new file mode 100644 index 00000000..7873bd29 --- /dev/null +++ b/cotisations/templates/cotisations/delete.html @@ -0,0 +1,16 @@ +{% extends "machines/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Création et modification de machines{% endblock %} + +{% block content %} + +
+ {% csrf_token %} +

Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?

+ {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %} +
+
+
+
+{% endblock %} diff --git a/cotisations/views.py b/cotisations/views.py index 6cc533c6..2975e97e 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -147,9 +147,11 @@ def del_facture(request, factureid): if (facture.control or not facture.valid): messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier") return redirect("/cotisations/") - facture.delete() - messages.success(request, "La facture a bien été supprimée") - return redirect("/cotisations/") + if request.method == "POST": + facture.delete() + messages.success(request, "La facture a été détruite") + return redirect("/cotisations/") + return form({'objet': facture, 'objet_name': 'facture'}, 'cotisations/delete.html', request) @login_required @permission_required('trésorier') diff --git a/machines/migrations/0019_auto_20160718_1141.py b/machines/migrations/0019_auto_20160718_1141.py new file mode 100644 index 00000000..bd99efb6 --- /dev/null +++ b/machines/migrations/0019_auto_20160718_1141.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0018_auto_20160708_1813'), + ] + + operations = [ + migrations.AlterField( + model_name='interface', + name='machine', + field=models.ForeignKey(to='machines.Machine'), + ), + ] diff --git a/machines/templates/machines/delete.html b/machines/templates/machines/delete.html new file mode 100644 index 00000000..7873bd29 --- /dev/null +++ b/machines/templates/machines/delete.html @@ -0,0 +1,16 @@ +{% extends "machines/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Création et modification de machines{% endblock %} + +{% block content %} + +
+ {% csrf_token %} +

Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?

+ {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %} +
+
+
+
+{% endblock %} diff --git a/machines/views.py b/machines/views.py index a8989a46..1dcbf309 100644 --- a/machines/views.py +++ b/machines/views.py @@ -135,9 +135,11 @@ def del_machine(request, machineid): if machine.user != request.user: messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") return redirect("/users/profil/" + str(request.user.id)) - machine.delete() - messages.success(request, "La machine a été détruite") - return redirect("/users/profil/" + str(request.user.id)) + if request.method == "POST": + machine.delete() + messages.success(request, "La machine a été détruite") + return redirect("/users/profil/" + str(request.user.id)) + return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request) @login_required def new_interface(request, machineid): @@ -175,9 +177,11 @@ def del_interface(request, interfaceid): if interface.machine.user != request.user: messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") return redirect("/users/profil/" + str(request.user.id)) - interface.delete() - messages.success(request, "L'interface a été détruite") - return redirect("/users/profil/" + str(request.user.id)) + if request.method == "POST": + interface.delete() + messages.success(request, "L'interface a été détruite") + return redirect("/users/profil/" + str(request.user.id)) + return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request) @login_required @permission_required('infra') diff --git a/topologie/migrations/0017_auto_20160718_1141.py b/topologie/migrations/0017_auto_20160718_1141.py new file mode 100644 index 00000000..6fdc0b6b --- /dev/null +++ b/topologie/migrations/0017_auto_20160718_1141.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0016_auto_20160706_1531'), + ] + + operations = [ + migrations.AlterField( + model_name='port', + name='machine_interface', + field=models.OneToOneField(to='machines.Interface', on_delete=django.db.models.deletion.SET_NULL, null=True, blank=True), + ), + ] diff --git a/topologie/models.py b/topologie/models.py index 717d15ea..8eba55a3 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -29,7 +29,7 @@ class Port(models.Model): switch = models.ForeignKey('Switch', related_name="ports") port = models.IntegerField() room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True) - machine_interface = models.OneToOneField('machines.Interface', on_delete=models.PROTECT, blank=True, null=True) + machine_interface = models.OneToOneField('machines.Interface', on_delete=models.SET_NULL, blank=True, null=True) related = models.OneToOneField('self', null=True, blank=True, related_name='related_port') details = models.CharField(max_length=255, blank=True)