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.
3 from .serializing import SerializingObject
6 class TaskFilter(object):
8 Abstract base class that defines interface of a TaskFilter.
12 def add_filter(self, arg):
14 Processes an non-keyword filter.
19 def add_filter_param(self, key, value):
21 Processes a keyword filter.
28 Returns a new deep copy of itself.
33 class TaskWarriorFilter(TaskFilter, SerializingObject):
35 A set of parameters to filter the task list with.
38 def __init__(self, backend, filter_params=None):
39 self.filter_params = filter_params or []
40 super(TaskFilter, self).__init__(backend)
42 def add_filter(self, filter_str):
43 self.filter_params.append(filter_str)
45 def add_filter_param(self, key, value):
46 key = key.replace('__', '.')
48 # Replace the value with empty string, since that is the
49 # convention in TW for empty values
50 attribute_key = key.split('.')[0]
52 # Since this is user input, we need to normalize before we serialize
53 value = self._normalize(attribute_key, value)
54 value = self._serialize(attribute_key, value)
56 # If we are filtering by uuid:, do not use uuid keyword
59 self.filter_params.insert(0, value)
61 # Surround value with aphostrophes unless it's a empty string
62 value = "'%s'" % value if value else ''
64 # We enforce equality match by using 'is' (or 'none') modifier
65 # Without using this syntax, filter fails due to TW-1479
66 # which is, however, fixed in 2.4.5
67 if self.backend.version < self.backend.VERSION_2_4_5:
68 modifier = '.is' if value else '.none'
69 key = key + modifier if '.' not in key else key
71 self.filter_params.append(six.u("{0}:{1}").format(key, value))
73 def get_filter_params(self):
74 return [f for f in self.filter_params if f]
77 c = self.__class__(self.backend)
78 c.filter_params = list(self.filter_params)