Browse Source

Overriding delete_selected to cleanly delete VPNs objects from LDAP.

Hugo Lefeuvre 10 years ago
parent
commit
1ff4fa2f0a
2 changed files with 12 additions and 2 deletions
  1. 6 0
      coin/utils.py
  2. 6 2
      coin/vpn/admin.py

+ 6 - 0
coin/utils.py

@@ -67,3 +67,9 @@ def send_templated_email(subject, to, template_to_use, context, attachements, fr
 
     #Send email
     msg.send()
+
+def delete_atomic(modeladmin, request, queryset):
+    """Overrides QuerySet's delete() function to remove objects one by one 
+    so, that they are deleted in the LDAP (Redmine issue #195)."""
+    for obj in queryset:
+        obj.delete()

+ 6 - 2
coin/vpn/admin.py

@@ -4,7 +4,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin
 
 from coin.vpn.models import VPNConfiguration
 from coin.configuration.admin import ConfigurationAdminFormMixin
-
+from coin.utils import delete_atomic
 
 class VPNConfigurationInline(admin.StackedInline):
     model = VPNConfiguration
@@ -22,7 +22,7 @@ class VPNConfigurationAdmin(ConfigurationAdminFormMixin, PolymorphicChildModelAd
                      'administrative_subscription__member__first_name',
                      'administrative_subscription__member__last_name',
                      'administrative_subscription__member__email')
-    actions = ("generate_endpoints", "generate_endpoints_v4",
+    actions = ("delete_selected", "generate_endpoints", "generate_endpoints_v4",
                "generate_endpoints_v6", "activate", "deactivate")
     exclude = ("password",)
     inline = VPNConfigurationInline
@@ -33,6 +33,10 @@ class VPNConfigurationAdmin(ConfigurationAdminFormMixin, PolymorphicChildModelAd
         else:
             return []
 
+    def delete_selected(self, *args):
+        delete_atomic(*args)
+    delete_selected.short_description = "Supprimer tous les objets sélectionnés."
+
     def set_activation(self, request, queryset, value):
         count = 0
         # We must update each object individually, because we want to run