All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 from tasklib.serializing import SerializingObject
5 class TaskFilter(object):
7 Abstract base class that defines interface of a TaskFilter.
11 def add_filter(self, arg):
13 Processes an non-keyword filter.
18 def add_filter_param(self, key, value):
20 Processes a keyword filter.
27 Returns a new deep copy of itself.
32 class TaskWarriorFilter(TaskFilter, SerializingObject):
34 A set of parameters to filter the task list with.
37 def __init__(self, warrior, filter_params=None):
38 self.filter_params = filter_params or []
39 super(TaskFilter, self).__init__(warrior)
41 def add_filter(self, filter_str):
42 self.filter_params.append(filter_str)
44 def add_filter_param(self, key, value):
45 key = key.replace('__', '.')
47 # Replace the value with empty string, since that is the
48 # convention in TW for empty values
49 attribute_key = key.split('.')[0]
51 # Since this is user input, we need to normalize before we serialize
52 value = self._normalize(attribute_key, value)
53 value = self._serialize(attribute_key, value)
55 # If we are filtering by uuid:, do not use uuid keyword
58 self.filter_params.insert(0, value)
60 # Surround value with aphostrophes unless it's a empty string
61 value = "'%s'" % value if value else ''
63 # We enforce equality match by using 'is' (or 'none') modifier
64 # Without using this syntax, filter fails due to TW-1479
65 # which is, however, fixed in 2.4.5
66 if self.warrior.version < VERSION_2_4_5:
67 modifier = '.is' if value else '.none'
68 key = key + modifier if '.' not in key else key
70 self.filter_params.append(six.u("{0}:{1}").format(key, value))
72 def get_filter_params(self):
73 return [f for f in self.filter_params if f]
76 c = self.__class__(self.warrior)
77 c.filter_params = list(self.filter_params)