X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/c76406e46e71cb86cfb440667bfbbe21b36e709e..49d0961a6f7f585f707cd08817f3e0a9f1a19212:/forum/models/node.py?ds=sidebyside diff --git a/forum/models/node.py b/forum/models/node.py index ea83e7f..69c6396 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -78,13 +78,10 @@ class NodeMetaClass(BaseMetaClass): return node_cls.objects.filter(parent=self) def parent(self): - p = self.__dict__.get('_%s_cache' % name, None) + if (self.parent is not None) and self.parent.node_type == name: + return self.parent.leaf - if p is None and (self.parent is not None) and self.parent.node_type == name: - p = self.parent.leaf - self.__dict__['_%s_cache' % name] = p - - return p + return None Node.add_to_class(name + 's', property(children)) Node.add_to_class(name, property(parent)) @@ -108,6 +105,30 @@ class NodeQuerySet(CachedQuerySet): return node + def any_state(self, *args): + filter = None + + for s in args: + s_filter = models.Q(state_string__contains="(%s)" % s) + filter = filter and (filter | s_filter) or s_filter + + if filter: + return self.filter(filter) + else: + return self + + def all_states(self, *args): + filter = None + + for s in args: + s_filter = models.Q(state_string__contains="(%s)" % s) + filter = filter and (filter & s_filter) or s_filter + + if filter: + return self.filter(filter) + else: + return self + def filter_state(self, **kwargs): apply_bool = lambda q, b: b and q or ~q return self.filter(*[apply_bool(models.Q(state_string__contains="(%s)" % s), b) for s, b in kwargs.items()]) @@ -223,7 +244,7 @@ class Node(BaseModel, NodeContent): @classmethod def _generate_cache_key(cls, key, group="node"): return super(Node, cls)._generate_cache_key(key, group) - + @classmethod def get_type(cls): return cls.__name__.lower() @@ -259,6 +280,13 @@ class Node(BaseModel, NodeContent): return nis + @property + def last_activity(self): + try: + return self.actions.order_by('-action_date')[0].action_date + except: + return self.last_seen + @property def state_list(self): return [s.state_type for s in self.states.all()]