+ def from_ldap(self, value, connection):
+ if len(value) == 0:
+ return ''
+ else:
+ return value[0].decode(connection.charset)
+
+ def get_db_prep_lookup(self, lookup_type, value):
+ "Returns field's value prepared for database lookup."
+ if lookup_type == 'endswith':
+ return ["*%s" % escape_ldap_filter(value)]
+ elif lookup_type == 'startswith':
+ return ["%s*" % escape_ldap_filter(value)]
+ elif lookup_type in ['contains', 'icontains']:
+ return ["*%s*" % escape_ldap_filter(value)]
+ elif lookup_type == 'exact':
+ return [escape_ldap_filter(value)]
+ elif lookup_type == 'in':
+ return [escape_ldap_filter(v) for v in value]
+
+ 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':
+ return "*%s" % escape_ldap_filter(value)
+ elif lookup_type == 'startswith':
+ return "%s*" % escape_ldap_filter(value)
+ elif lookup_type in ['contains', 'icontains']:
+ return "*%s*" % escape_ldap_filter(value)
+ elif lookup_type == 'exact':
+ return escape_ldap_filter(value)
+ elif lookup_type == 'in':
+ return [escape_ldap_filter(v) for v in value]
+
+ raise TypeError("CharField has invalid lookup: %s" % lookup_type)
+