Commit c261462b authored by Bram Schoenmakers's avatar Bram Schoenmakers

Move function to generate list of filters to Filter.

The function to generate a list of GrepFilters, OrdinalTagFilters
NegationFilters is needed by the new UI. Move this functionality
the ExpressionCommand to the Filter module.
parent 4c8390ea
......@@ -39,27 +39,11 @@ class ExpressionCommand(Command):
def _filters(self):
filters = []
def arg_filters():
result = []
for arg in self.args:
if re.match(Filter.ORDINAL_TAG_MATCH, arg):
argfilter = Filter.OrdinalTagFilter(arg)
elif len(arg) > 1 and arg[0] == '-':
# when a word starts with -, exclude it
argfilter = Filter.GrepFilter(arg[1:])
argfilter = Filter.NegationFilter(argfilter)
else:
argfilter = Filter.GrepFilter(arg)
result.append(argfilter)
return result
if not self.show_all:
filters.append(Filter.DependencyFilter(self.todolist))
filters.append(Filter.RelevanceFilter())
filters += arg_filters()
filters += Filter.get_filter_list(self.args)
if not self.show_all:
filters.append(Filter.LimitFilter(config().list_limit()))
......
......@@ -196,3 +196,24 @@ class OrdinalTagFilter(Filter):
return False
def get_filter_list(p_expression):
"""
Returns a list of GrepFilters, OrdinalTagFilters or NegationFilters based
on the given filter expression.
The filter expression is a list of strings.
"""
result = []
for arg in p_expression:
if re.match(ORDINAL_TAG_MATCH, arg):
argfilter = OrdinalTagFilter(arg)
elif len(arg) > 1 and arg[0] == '-':
# when a word starts with -, exclude it
argfilter = GrepFilter(arg[1:])
argfilter = NegationFilter(argfilter)
else:
argfilter = GrepFilter(arg)
result.append(argfilter)
return result
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