fix and test deletion from admin interface
[matthijs/upstream/django-ldapdb.git] / ldapdb / models / base.py
index 9a132d8199ff825daf902656a7a565e19b4749ed..41d00e8c684b3fa7483973a5478b888808cce290 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 # 
 # django-ldapdb
-# Copyright (C) 2009 BollorĂ© telecom
+# Copyright (C) 2009-2010 BollorĂ© telecom
 # See AUTHORS file for a full list of contributors.
 # 
 # This program is free software: you can redistribute it and/or modify
@@ -18,8 +18,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-# -*- coding: utf-8 -*-
-
 import ldap
 import logging
 
@@ -62,6 +60,12 @@ class Model(django.db.models.base.Model):
         super(Model, self).__init__(*args, **kwargs)
         self.saved_pk = self.pk
 
+    def _collect_sub_objects(self, collector):
+        """
+        This private API seems to be called by the admin interface in django 1.2
+        """
+        pass
+
     def build_rdn(self):
         """
         Build the Relative Distinguished Name for this entry.
@@ -101,7 +105,7 @@ class Model(django.db.models.base.Model):
                     continue
                 value = getattr(self, field.name)
                 if value:
-                    entry.append((field.db_column, value))
+                    entry.append((field.db_column, field.get_db_prep_save(value, connection=ldapdb.connection)))
 
             logging.debug("Creating new LDAP entry %s" % new_dn)
             ldapdb.connection.add_s(new_dn, entry)
@@ -121,7 +125,7 @@ class Model(django.db.models.base.Model):
                 new_value = getattr(self, field.name, None)
                 if old_value != new_value:
                     if new_value:
-                        modlist.append((ldap.MOD_REPLACE, field.db_column, new_value))
+                        modlist.append((ldap.MOD_REPLACE, field.db_column, field.get_db_prep_save(new_value, connection=ldapdb.connection)))
                     elif old_value:
                         modlist.append((ldap.MOD_DELETE, field.db_column, None))