<commit_before>from django import template
from django.core.urlresolvers import reverse

import re

register = template.Library()

"""
For some reason this code is breaking on iteration through the 
all issues view.  It seems like the variable issue that serves 
as a holder for iteration, doesn't change from the previously 
set machine_string and messes up the next iteration if there is 
no item associated with the issue
"""

class LookupMachineNode(template.Node):
    def __init__(self, machine_string):
        self.machine_string = machine_string

    def render(self, context):

        if type(self.machine_string) == unicode:
            return 'None'
        
        self.machine_string = self.machine_string.resolve(context)
        return "<a href=\"%s\">%s</a>" % (reverse('history', args=[self.machine_string]), self.machine_string)

@register.tag('lookup_machine')
def lookup_machine(parser, token):
    try:
        tag_name, machine_string = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return LookupMachineNode(parser.compile_filter(machine_string))

class SearchHeader(template.Node):
    def __init__(self, col_name, id):
        self.name = col_name
        self.id = id

    def render(self, context):
        return """
        <th class='r_%s'>
            <a href="?orderby=%s&ometh=%s">%s</a>
        </th>""" % (self.id, self.id, context['omethod'], self.name)

def stripQuotes(str):
    if (str[0] == str[-1] and str[0] == '"'):
        return str[1:-1]
    return str


@register.tag('searchcolumn')
def column_header(parser, token):
    try:
        tag_name, id, col_name = token.split_contents()
        id = stripQuotes(id)
        col_name = stripQuotes(col_name)
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return SearchHeader(col_name, id)<commit_msg>Using template.Variable to resolve passed args<commit_after>from django import template
from django.core.urlresolvers import reverse

import re

register = template.Library()

"""
For some reason this code is breaking on iteration through the 
all issues view.  It seems like the variable issue that serves 
as a holder for iteration, doesn't change from the previously 
set machine_string and messes up the next iteration if there is 
no item associated with the issue
"""

class LookupMachineNode(template.Node):
    def __init__(self, machine_string):
        self.machine_string = machine_string

    def render(self, context):

        if type(self.machine_string) == unicode:
            return 'None'
        
        self.machine_string = self.machine_string.resolve(context)
        return "<a href=\"%s\">%s</a>" % (reverse('history', args=[self.machine_string]), self.machine_string)

@register.tag('lookup_machine')
def lookup_machine(parser, token):
    try:
        tag_name, machine_string = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return LookupMachineNode(parser.compile_filter(machine_string))

class SearchHeader(template.Node):
    def __init__(self, col_name, id):
        self.name = col_name
        self.id = id

    def render(self, context):
        return """
        <th class='r_%s'>
            <a href="?orderby=%s&ometh=%s">%s</a>
        </th>""" % (self.id, self.id.resolve(context), context['omethod'], self.name.resolve(context))

@register.tag('searchcolumn')
def column_header(parser, token):
    try:
        tag_name, id, col_name = token.split_contents()
        id, col_name = map(template.Variable, [id, col_name])
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return SearchHeader(col_name, id)
{'fraction_non_alphanumeric': 0.11379222758445517, 'fraction_numerical': 0.002286004572009144, 'mean_word_length': 3.5684454756380513, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '399679', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1129, 'n_words': 326}