Commit fdd87025 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Merge branch 'case-insensitive-filter' of https://github.com/jnga/flask-admin...

Merge branch 'case-insensitive-filter' of https://github.com/jnga/flask-admin into case-insensitive-mongo
parents 1f3d1b72 6bf28ccf
def parse_like_term(term): def parse_like_term(term):
""" """
Parse search term into (operation, term) tuple. Recognizes operators Parse search term into (operation, term) tuple. Recognizes operators
in the beginning of the search term. in the beginning of the search term. Case insensitive is the default.
* = case insensitive (can precede other operators) * = case sensitive (can precede other operators)
^ = starts with ^ = starts with
= = exact = = exact
:param term: :param term:
Search term Search term
""" """
case_insensitive = term.startswith('*') case_sensitive = term.startswith('*')
if case_insensitive: if case_sensitive:
term = term[1:] term = term[1:]
# apply operators # apply operators
if term.startswith('^'): if term.startswith('^'):
...@@ -23,6 +23,6 @@ def parse_like_term(term): ...@@ -23,6 +23,6 @@ def parse_like_term(term):
else: else:
oper = 'contains' oper = 'contains'
# add case insensitive flag # add case insensitive flag
if case_insensitive: if not case_sensitive:
oper = 'i' + oper oper = 'i' + oper
return oper, term return oper, term
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment