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
34 def __eq__(self, other):
36 # For saved Tasks, just define equality by equality of uuids
37 return self['uuid'] == other['uuid']
40 return self['uuid'].__hash__()
44 Performs conversion to the regular Task object, referenced by the
48 replacement = self._tw.tasks.get(uuid=self._uuid)
49 self.__class__ = replacement.__class__
50 self.__dict__ = replacement.__dict__
53 class LazyUUIDTaskSet(object):
55 A lazy wrapper around TaskQuerySet object, for tasks referenced by UUID.
57 - Supports 'in' operator with LazyUUIDTask or Task objects
58 - If iteration over the objects in the LazyUUIDTaskSet is requested, the
59 LazyUUIDTaskSet will be converted to QuerySet and evaluated
62 def __init__(self, tw, uuids):
64 self._uuids = set(uuids)
66 def __getattr__(self, name):
67 # Getattr is called only if the attribute could not be found using
70 if name.startswith('__'):
71 # If some internal method was being search, do not convert
72 # to TaskQuerySet just because of that
78 def __eq__(self, other):
79 return set(t['uuid'] for t in other) == self._uuids
81 def __contains__(self, task):
82 return task['uuid'] in self._uuids
85 return len(self._uuids)
88 for uuid in self._uuids:
89 yield LazyUUIDTask(self._tw, uuid)
93 Performs conversion to the regular TaskQuerySet object, referenced by
97 replacement = self._tw.tasks.filter(' '.join(self._uuids))
98 self.__class__ = replacement.__class__
99 self.__dict__ = replacement.__dict__