<commit_before>from django import template
from django.template.defaultfilters import stringfilter
from currencies.models import Currency
from currencies.utils import calculate_price, convert

register = template.Library()


@register.filter(name='currency')
@stringfilter
def set_currency(value, arg):
    return calculate_price(value, arg)


class ChangeCurrencyNode(template.Node):

    def __init__(self, price, currency):
        self.price = template.Variable(price)
        self.currency = template.Variable(currency)

    def render(self, context):
        try:
            return calculate_price(self.price.resolve(context),
                self.currency.resolve(context))
        except template.VariableDoesNotExist:
            return ''

@register.tag(name='change_currency')
def change_currency(parser, token):
    try:
        tag_name, current_price, new_currency = token.split_contents()
    except ValueError:
        tag_name = token.contents.split()[0]
        raise template.TemplateSyntaxError('%r tag requires exactly two arguments' % (tag_name))
    return ChangeCurrencyNode(current_price, new_currency)


@register.simple_tag(name='currency_convert')
def my_tag(amount, from_, to_, *args, **kwargs):
    return convert(amount, from_, to_)
    
<commit_msg>Name the template tag for conversion correctly, and some PEP8 tidy ups<commit_after>from django import template
from django.template.defaultfilters import stringfilter
from currencies.utils import calculate_price, convert

register = template.Library()


@register.filter(name='currency')
@stringfilter
def set_currency(value, arg):
    return calculate_price(value, arg)


class ChangeCurrencyNode(template.Node):

    def __init__(self, price, currency):
        self.price = template.Variable(price)
        self.currency = template.Variable(currency)

    def render(self, context):
        try:
            return calculate_price(self.price.resolve(context),
                self.currency.resolve(context))
        except template.VariableDoesNotExist:
            return ''


@register.tag(name='change_currency')
def change_currency(parser, token):
    try:
        tag_name, current_price, new_currency = token.split_contents()
    except ValueError:
        tag_name = token.contents.split()[0]
        raise template.TemplateSyntaxError('%r tag requires exactly two arguments' % (tag_name))
    return ChangeCurrencyNode(current_price, new_currency)


@register.simple_tag(name='currency_convert')
def currency_convert(amount, from_, to_, *args, **kwargs):
    return convert(amount, from_, to_)

{'fraction_non_alphanumeric': 0.09659969088098919, 'fraction_numerical': 0.00115919629057187, 'mean_word_length': 4.147117296222664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4894707', 'n_tokens_mistral': 700, 'n_tokens_neox': 684, 'n_words': 171}