diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -58,6 +58,7 @@ POST_VIEW_PARAMS = ( 'truncated', 'mode_tree', 'perms', + 'tree_depth', ) diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -279,3 +279,20 @@ class Thread(models.Model): if len(parents) > 0: self.tags.add(*parents) + def get_reply_tree(self): + replies = self.get_replies().prefetch_related('refposts') + tree = [] + for reply in replies: + parents = reply.refposts.all() + found_parent = False + if len(parents) > 0: + index = 0 + for depth, element in tree: + index += 1 + if element in parents: + tree.insert(index, (depth + 1, reply)) + found_parent = True + if not found_parent: + tree.append((0, reply)) + + return tree diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -3,7 +3,7 @@ {% get_current_language as LANGUAGE_CODE %} -