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 Provides lazy implementations for Task and TaskQuerySet.
6 class LazyUUIDTask(object):
8 A lazy wrapper around Task object, referenced by UUID.
10 - Supports comparison with LazyUUIDTask or Task objects (equality by UUIDs)
11 - If any attribute other than 'uuid' requested, a lookup in the
12 backend will be performed and this object will be replaced by a proper
16 def __init__(self, tw, uuid):
20 def __getitem__(self, key):
21 # LazyUUIDTask does not provide anything else other than 'uuid'
28 def __getattr__(self, name):
29 # Getattr is called only if the attribute could not be found using
32 return getattr(self, name)
34 def __eq__(self, other):
35 if other and other['uuid']:
36 # For saved Tasks, just define equality by equality of uuids
37 return self['uuid'] == other['uuid']
40 return self['uuid'].__hash__()
43 return 'LazyUUIDTask: {0}'.format(self._uuid)
46 return LazyUUIDTask(self._tw, self._uuid)
48 def __deepcopy__(self, memo):
49 return LazyUUIDTask(self._tw, self._uuid)
54 Implementation of the 'saved' property. Always returns True.
59 def _modified_fields(self):
68 Performs conversion to the regular Task object, referenced by the
72 replacement = self._tw.tasks.get(uuid=self._uuid)
73 self.__class__ = replacement.__class__
74 self.__dict__ = replacement.__dict__
77 class LazyUUIDTaskSet(object):
79 A lazy wrapper around TaskQuerySet object, for tasks referenced by UUID.
81 - Supports 'in' operator with LazyUUIDTask or Task objects
82 - If iteration over the objects in the LazyUUIDTaskSet is requested, the
83 LazyUUIDTaskSet will be converted to QuerySet and evaluated
86 def __init__(self, tw, uuids):
88 self._uuids = set(uuids)
90 def __getattr__(self, name):
91 # Getattr is called only if the attribute could not be found using
94 if name.startswith('__'):
95 # If some internal method was being search, do not convert
96 # to TaskQuerySet just because of that
100 return getattr(self, name)
103 return 'LazyUUIDTaskSet([{0}])'.format(', '.join(self._uuids))
105 def __eq__(self, other):
106 return set(t['uuid'] for t in other) == self._uuids
108 def __ne__(self, other):
109 return not (self == other)
111 def __contains__(self, task):
112 return task['uuid'] in self._uuids
115 return len(self._uuids)
118 for uuid in self._uuids:
119 yield LazyUUIDTask(self._tw, uuid)
121 def __sub__(self, other):
122 return self.difference(other)
124 def __isub__(self, other):
125 return self.difference_update(other)
127 def __rsub__(self, other):
128 return LazyUUIDTaskSet(
130 set(t['uuid'] for t in other) - self._uuids,
133 def __or__(self, other):
134 return self.union(other)
136 def __ior__(self, other):
137 return self.update(other)
139 def __ror__(self, other):
140 return self.union(other)
142 def __xor__(self, other):
143 return self.symmetric_difference(other)
145 def __ixor__(self, other):
146 return self.symmetric_difference_update(other)
148 def __rxor__(self, other):
149 return self.symmetric_difference(other)
151 def __and__(self, other):
152 return self.intersection(other)
154 def __iand__(self, other):
155 return self.intersection_update(other)
157 def __rand__(self, other):
158 return self.intersection(other)
160 def __le__(self, other):
161 return self.issubset(other)
163 def __ge__(self, other):
164 return self.issuperset(other)
166 def issubset(self, other):
167 return all([task in other for task in self])
169 def issuperset(self, other):
170 return all([task in self for task in other])
172 def union(self, other):
173 return LazyUUIDTaskSet(
175 self._uuids | set(t['uuid'] for t in other),
178 def intersection(self, other):
179 return LazyUUIDTaskSet(
181 self._uuids & set(t['uuid'] for t in other),
184 def difference(self, other):
185 return LazyUUIDTaskSet(
187 self._uuids - set(t['uuid'] for t in other),
190 def symmetric_difference(self, other):
191 return LazyUUIDTaskSet(
193 self._uuids ^ set(t['uuid'] for t in other),
196 def update(self, other):
197 self._uuids |= set(t['uuid'] for t in other)
200 def intersection_update(self, other):
201 self._uuids &= set(t['uuid'] for t in other)
204 def difference_update(self, other):
205 self._uuids -= set(t['uuid'] for t in other)
208 def symmetric_difference_update(self, other):
209 self._uuids ^= set(t['uuid'] for t in other)
213 self._uuids.add(task['uuid'])
215 def remove(self, task):
216 self._uuids.remove(task['uuid'])
219 return self._uuids.pop()
226 Performs conversion to the regular TaskQuerySet object, referenced by
230 replacement = self._tw.tasks.filter(' '.join(self._uuids))
231 self.__class__ = replacement.__class__
232 self.__dict__ = replacement.__dict__