From 4abdee082b2cb5697cf0e6436df871a36cccdbe6 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 31 May 2010 19:43:24 +0000 Subject: [PATCH] implement and test bulk deletion git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@909 e071eeec-0327-468d-9b6a-08194a12b294 --- examples/tests.py | 6 ++++++ ldapdb/models/query.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/examples/tests.py b/examples/tests.py index 465c857..e108852 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -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') diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 0d4b0e1..4f0273c 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -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) + -- 2.30.2