def get_thread(cls, anchor_uri, user): """ Returns a tree of comments. """ comments = cls._default_manager.filter(anchor_uri=anchor_uri) map = {"root": []} for comment in comments: value = Vote.value_for(comment, user=user) # TODO: Cache this if (value > 0): comment.up = True if (value < 0): comment.down = True comment.thread = map.setdefault(comment.id, []) map.setdefault(comment.parent_id or "root", []).append(comment) return map["root"]
def fix_value(self): self.value = Vote.value_for(self)