From e8e93ed4bee8b0a3428f88a4f020aa08bdad806d Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 14 Dec 2016 18:09:24 +0100 Subject: [PATCH] Supprime les machines orphelines --- machines/models.py | 4 ++- machines/views.py | 3 ++ .../migrations/0022_auto_20161211_1622.py | 19 ++++++++++++ users/migrations/0042_auto_20161126_2028.py | 29 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 topologie/migrations/0022_auto_20161211_1622.py create mode 100644 users/migrations/0042_auto_20161126_2028.py diff --git a/machines/models.py b/machines/models.py index 0bd879d7..30494cd1 100644 --- a/machines/models.py +++ b/machines/models.py @@ -137,5 +137,7 @@ def interface_post_save(sender, **kwargs): @receiver(post_delete, sender=Interface) def interface_post_delete(sender, **kwargs): - user = kwargs['instance'].machine.user + interface = kwargs['instance'] + user = interface.machine.user user.ldap_sync(base=False, access_refresh=False, mac_refresh=True) + diff --git a/machines/views.py b/machines/views.py index 724168a7..7b07872d 100644 --- a/machines/views.py +++ b/machines/views.py @@ -217,8 +217,11 @@ def del_interface(request, interfaceid): 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)) if request.method == "POST": + machine = interface.machine with transaction.atomic(), reversion.create_revision(): interface.delete() + if not machine.interface_set.all(): + machine.delete() reversion.set_user(request.user) messages.success(request, "L'interface a été détruite") return redirect("/users/profil/" + str(request.user.id)) diff --git a/topologie/migrations/0022_auto_20161211_1622.py b/topologie/migrations/0022_auto_20161211_1622.py new file mode 100644 index 00000000..dfcd1524 --- /dev/null +++ b/topologie/migrations/0022_auto_20161211_1622.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0021_port_radius'), + ] + + operations = [ + migrations.AlterField( + model_name='port', + name='radius', + field=models.CharField(max_length=32, default='NO', choices=[('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON'), ('7', '7'), ('8', '8'), ('42', '42'), ('69', '69')]), + ), + ] diff --git a/users/migrations/0042_auto_20161126_2028.py b/users/migrations/0042_auto_20161126_2028.py new file mode 100644 index 00000000..3dd87426 --- /dev/null +++ b/users/migrations/0042_auto_20161126_2028.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0041_listright_details'), + ] + + operations = [ + migrations.AlterField( + model_name='ldapserviceuser', + name='dn', + field=models.CharField(serialize=False, primary_key=True, max_length=200), + ), + migrations.AlterField( + model_name='ldapuser', + name='dn', + field=models.CharField(serialize=False, primary_key=True, max_length=200), + ), + migrations.AlterField( + model_name='ldapusergroup', + name='dn', + field=models.CharField(serialize=False, primary_key=True, max_length=200), + ), + ]