Added regex match operators with test

This commit is contained in:
Harry Marr
2010-02-26 13:43:32 +00:00
parent ab2d019349
commit 66520c77f8
3 changed files with 60 additions and 4 deletions

View File

@@ -39,8 +39,25 @@ class StringField(BaseField):
def lookup_member(self, member_name):
return None
def prepare_query_value(self, op, value):
if not isinstance(op, basestring):
return value
class URLField(BaseField):
if op.lstrip('i') in ('startswith', 'endswith', 'contains'):
flags = 0
if op.startswith('i'):
flags = re.IGNORECASE
op = op.lstrip('i')
regex = r'%s'
if op == 'startswith':
regex = r'^%s'
elif op == 'endswith':
regex = r'%s$'
value = re.compile(regex % value, flags)
return value
class URLField(StringField):
"""A field that validates input as a URL.
"""