implement and test bulk deletion
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 19:43:24 +0000 (19:43 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 19:43:24 +0000 (19:43 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@909 e071eeec-0327-468d-9b6a-08194a12b294

examples/tests.py
ldapdb/models/query.py

index 465c857..e108852 100644 (file)
@@ -116,6 +116,12 @@ class GroupTestCase(BaseTestCase):
         self.assertEquals(qs[0].gid, 1001)
         self.assertEquals(qs[1].gid, 1000)
 
+    def test_bulk_delete(self):
+        LdapGroup.objects.all().delete()
+
+        qs = LdapGroup.objects.all()
+        self.assertEquals(len(qs), 0)
+
     def test_update(self):
         g = LdapGroup.objects.get(name='foogroup')
 
index 0d4b0e1..4f0273c 100644 (file)
@@ -214,3 +214,15 @@ class QuerySet(BaseQuerySet):
                 query = Query(model, None, WhereNode)
         super(QuerySet, self).__init__(model=model, query=query)
 
+    def delete(self):
+        "Bulk deletion."
+        vals = ldapdb.connection.search_s(
+            self.model.base_dn,
+            ldap.SCOPE_SUBTREE,
+            filterstr=self.query._ldap_filter(),
+            attrlist=[],
+        )
+        # FIXME : there is probably a more efficient way to do this 
+        for dn, attrs in vals:
+            ldapdb.connection.delete_s(dn)
+