<commit_before>import locale

from django import template
from django.conf import settings

register = template.Library()

@register.filter(name='currency')
def currency(value):
    """
    Return value converted to a locale currency
    """
    try:
        locale.setlocale(locale.LC_ALL, settings.LOCALE)
    except AttributeError:
        locale.setlocale(locale.LC_ALL, '')
        
    # We allow the currency symbol to be overridden    
    symbol = getattr(settings, 'CURRENCY_SYMBOL', None)
    try:
        if symbol:
            return u"%s%s" % (symbol, locale.format("%.2f", value, grouping=True))
        else:
            c = locale.currency(value, symbol=True, grouping=True)
            return unicode(c, 'utf8')
    except TypeError:
        return '' 
        <commit_msg>Display 'Free' for products with price 0<commit_after>import locale

from django import template
from django.conf import settings
from django.utils.translation import ugettext as _

register = template.Library()

@register.filter(name='currency')
def currency(value):
    """
    Return value converted to a locale currency
    """
    if not value:
        return getattr(settings, 'FREE_PRODUCT_PRICE_TEXT', _('Free'))
    try:
        locale.setlocale(locale.LC_ALL, settings.LOCALE)
    except AttributeError:
        locale.setlocale(locale.LC_ALL, '')

    # We allow the currency symbol to be overridden
    symbol = getattr(settings, 'CURRENCY_SYMBOL', None)
    try:
        if symbol:
            return u"%s%s" % (symbol, locale.format("%.2f", value, grouping=True))
        else:
            c = locale.currency(value, symbol=True, grouping=True)
            return unicode(c, 'utf8')
    except TypeError:
        return ''

{'fraction_non_alphanumeric': 0.10590277777777778, 'fraction_numerical': 0.0028935185185185184, 'mean_word_length': 2.868008948545861, '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': '6525349', 'n_tokens_mistral': 498, 'n_tokens_neox': 488, 'n_words': 138}