<commit_before>from django import template
from django.urls import reverse
from django.utils.safestring import mark_safe


from helpers.templatetags.frontend_extras import octicon


register = template.Library()


@register.simple_tag
def make_tree(posts, current_post=None):
    levels = []
    depth = 0
    html = '<ul>'

    for post in posts:
        try:
            while levels[-1] < post.left:
                html += '</ul></li>'
                levels.pop()
                depth -= 1
        except IndexError:
            pass

        if post == current_post:
            line = '<li>{icon}{title} by {user} on {date}'
        else:
            line = '<li><a href="{url}">{title}</a> by {user} on {date}'

        html += line.format(
                icon=octicon('arrow-right'),
                url=reverse('forum:post', kwargs={
                    'board':post.topic.board.slug,
                    'pk':post.pk
                    }),
                title=post.subject,
                user=post.user.username,
                date='[date]',
                )

        if post.right - post.left > 1:
            html += '<ul>'
            levels.append(post.right)
            depth = len(levels)
        else:
            html += '</li>'

    html += '</ul></li>' * depth
    html += '</ul>'

    return mark_safe(html)
<commit_msg>Display post tree with divs<commit_after>from django import template
from django.urls import reverse
from django.utils.safestring import mark_safe


from helpers.templatetags.frontend_extras import octicon


register = template.Library()


@register.simple_tag
def make_tree(posts, current_post=None):
    levels = []
    depth = 0
    html = '<div class="post-tree">'

    for post in posts:
        try:
            while levels[-1] < post.left:
                html += '</div>'
                levels.pop()
                depth -= 1
        except IndexError:
            pass

        if post == current_post:
            line = '<div>{icon}{title} by {user} on {date}'
        else:
            line = '<div><a href="{url}">{title}</a> by {user} on {date}'

        html += line.format(
                icon=octicon('arrow-right'),
                url=reverse('forum:post', kwargs={
                    'board':post.topic.board.slug,
                    'pk':post.pk
                    }),
                title=post.subject,
                user=post.user.username,
                date='[date]',
                )

        if post.right - post.left > 1:
            #html += '<ul>'
            levels.append(post.right)
            depth = len(levels)
        else:
            html += '</div>'

    html += '</div>' * depth
    html += '</div>'

    return mark_safe(html)

{'fraction_non_alphanumeric': 0.133406432748538, 'fraction_numerical': 0.0029239766081871343, 'mean_word_length': 1.5272391505078486, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5266979', 'n_tokens_mistral': 805, 'n_tokens_neox': 756, 'n_words': 183}