return DatabaseCursor(self.connection)
def add_s(self, dn, modlist):
- mods = []
- for field, value in modlist:
- converted = convert(field, value, lambda x: x.encode(self.charset))
- if isinstance(converted, list):
- mods.append((field, converted))
- else:
- mods.append((field, [converted]))
cursor = self._cursor()
- return cursor.connection.add_s(dn.encode(self.charset), mods)
+ return cursor.connection.add_s(dn.encode(self.charset), modlist)
def delete_s(self, dn):
cursor = self._cursor()
return cursor.connection.delete_s(dn.encode(self.charset))
def modify_s(self, dn, modlist):
- mods = []
- for op, field, value in modlist:
- mods.append((op, field, convert(field, value, lambda x: x.encode(self.charset))))
cursor = self._cursor()
- return cursor.connection.modify_s(dn.encode(self.charset), mods)
+ return cursor.connection.modify_s(dn.encode(self.charset), modlist)
def rename_s(self, dn, newrdn):
cursor = self._cursor()
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)
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))
raise TypeError("CharField has invalid lookup: %s" % lookup_type)
+ def get_db_prep_save(self, value, connection):
+ return [value.encode(connection.charset)]
+
def get_prep_lookup(self, lookup_type, value):
"Perform preliminary non-db specific lookup checks and conversions"
if lookup_type == 'endswith':
"Returns field's value prepared for database lookup."
return [self.get_prep_lookup(lookup_type, value)]
+ def get_db_prep_save(self, value, connection):
+ return [value]
+
def get_prep_lookup(self, lookup_type, value):
"Perform preliminary non-db specific lookup checks and conversions"
raise TypeError("ImageField has invalid lookup: %s" % lookup_type)
"Returns field's value prepared for database lookup."
return [self.get_prep_lookup(lookup_type, value)]
+ def get_db_prep_save(self, value, connection):
+ return [str(value)]
+
def get_prep_lookup(self, lookup_type, value):
"Perform preliminary non-db specific lookup checks and conversions"
if lookup_type in ('exact', 'gte', 'lte'):
"Returns field's value prepared for database lookup."
return [self.get_prep_lookup(lookup_type, value)]
+ def get_db_prep_save(self, value, connection):
+ return [x.encode(connection.charset) for x in value]
+
def get_prep_lookup(self, lookup_type, value):
"Perform preliminary non-db specific lookup checks and conversions"
if lookup_type == 'contains':