# -*- 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
kwargs['max_length'] = 200
super(CharField, self).__init__(*args, **kwargs)
+ def get_db_prep_lookup(self, lookup_type, value):
+ if lookup_type == 'endswith':
+ return ["*%s" % escape_ldap_filter(value)]
+ elif lookup_type == 'startswith':
+ return ["%s*" % escape_ldap_filter(value)]
+ elif lookup_type == 'contains':
+ 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_prep_lookup(self, lookup_type, value):
return escape_ldap_filter(value)
class ImageField(fields.Field):
- pass
+ def get_db_prep_lookup(self, lookup_type, value):
+ raise TypeError("ImageField has invalid lookup: %s" % lookup_type)
class IntegerField(fields.IntegerField):
- pass
+ def get_db_prep_lookup(self, lookup_type, value):
+ if lookup_type in ('exact', 'gte', 'lte'):
+ return [value]
+
+ raise TypeError("IntegerField has invalid lookup: %s" % lookup_type)
class ListField(fields.Field):
__metaclass__ = SubfieldBase
+ def get_db_prep_lookup(self, lookup_type, value):
+ raise TypeError("ListField has invalid lookup: %s" % lookup_type)
+
def to_python(self, value):
if not value:
return []