# HG changeset patch # User neko259 # Date 2016-02-04 15:59:20 # Node ID d5bf9a5c7fe92ed48a081b4a7f88e4e06e24c8e6 # Parent 10f7aa62595224089f842f6cf168dfc44d6c4a9a New fast recursion-free tree render engine 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 %} -
+
{% if post.is_referenced %} - {% if mode_tree %} -
- {% for refpost in post.get_referenced_posts %} - {% post_view refpost mode_tree=True %} - {% endfor %} -
- {% else %} + {% if not mode_tree %}
{% trans "Replies" %}: {{ post.refmap|safe }}
diff --git a/boards/templates/boards/thread_tree.html b/boards/templates/boards/thread_tree.html --- a/boards/templates/boards/thread_tree.html +++ b/boards/templates/boards/thread_tree.html @@ -10,8 +10,8 @@ {% get_current_timezone as TIME_ZONE %}
- {% for post in thread.get_top_level_replies %} - {% post_view post mode_tree=True %} + {% for depth, post in thread.get_reply_tree %} + {% post_view post mode_tree=True tree_depth=depth%} {% endfor %}