<commit_before>from django import template
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from apps.issues.models import IssueCategory

register = template.Library()

@register.filter(needs_autoescape=True)
def render_question_tree(question, autoescape=True):
	e = conditional_escape if autoescape else lambda x: x
	return mark_safe(recurse_tree(question, e))

def recurse_tree(question, escape):
	if question is None:
		return render_input()
	
	if type(question) == IssueCategory:
		return render_category(question, escape)

	markup = """
<div data-id="{id}" class="qb_question">
		<button class="btn btn-danger btn-xs remove_question"><span class="glyphicon glyphicon-remove"></span></button>
		<span class="qb_question_title">{question}</span>
		<ul>
			<li class="yes">{yes}</li>
			<li class="no">{no}</li>
		</ul>
</div>
"""
	yes = recurse_tree(question.get_yes(), escape)
	no = recurse_tree(question.get_no(), escape)

	return markup.format(id=question.id, question=question.question, yes=yes, no=no)

def render_category(category, escape):
	t = """<div><button class="btn btn-danger btn-xs remove_category"><span class="glyphicon glyphicon-remove"></span></button> <span class="qb_category">{name}</span></div>"""
	return t.format(name=escape(category.name), id=escape(category.id))

def render_input():
	return """<div class="input-group" style="width:300px">
	<input type="text" class="form-control new_text" placeholder="Add question or category...">
	<span class="input-group-btn">
		<button class="btn btn-primary save_button" type="button"><span class="glyphicon glyphicon-plus"></span></button>
	</span>
</div>"""<commit_msg>Tabs -> spaces on templatetags<commit_after>from django import template
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from apps.issues.models import IssueCategory

register = template.Library()

@register.filter(needs_autoescape=True)
def render_question_tree(question, autoescape=True):
    e = conditional_escape if autoescape else lambda x: x
    return mark_safe(recurse_tree(question, e))

def recurse_tree(question, escape):
    if question is None:
        return render_input()
    
    if type(question) == IssueCategory:
        return render_category(question, escape)

    markup = """
<div data-id="{id}" class="qb_question">
        <button class="btn btn-danger btn-xs remove_question"><span class="glyphicon glyphicon-remove"></span></button>
        <span class="qb_question_title">{question}</span>
        <ul>
            <li class="yes">{yes}</li>
            <li class="no">{no}</li>
        </ul>
</div>
"""
    yes = recurse_tree(question.get_yes(), escape)
    no = recurse_tree(question.get_no(), escape)

    return markup.format(id=question.id, question=question.question, yes=yes, no=no)

def render_category(category, escape):
    t = """<div><button class="btn btn-danger btn-xs remove_category"><span class="glyphicon glyphicon-remove"></span></button> <span class="qb_category">{name}</span></div>"""
    return t.format(name=escape(category.name), id=escape(category.id))

def render_input():
    return """<div class="input-group" style="width:300px">
    <input type="text" class="form-control new_text" placeholder="Add question or category...">
    <span class="input-group-btn">
        <button class="btn btn-primary save_button" type="button"><span class="glyphicon glyphicon-plus"></span></button>
    </span>
</div>"""
{'fraction_non_alphanumeric': 0.15551743853630645, 'fraction_numerical': 0.0017152658662092624, 'mean_word_length': 5.396709323583181, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 66, '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': '7537880', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1075, 'n_words': 242}