import locale
from decimal import Decimal

from django import template

locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
register = template.Library()

@register.filter
def money_format(value):
    """
    Display float in money-style format with specified decimal places and
    comma-grouped thousands.
    """
    return locale.currency(Decimal(str(value)), grouping=True)

@@ -1,18 +1,4 @@
-import locale%0A
 from
@@ -55,55 +55,8 @@
 te%0A%0A
-locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')%0A
 regi
@@ -243,71 +243,592 @@
     
-%22%22%22%0A    return locale.currency(Decimal(str(value)), grouping=True
+Adapted from https://docs.python.org/2/library/decimal.html#recipes%0A    %22%22%22%0A    q = Decimal(10) ** -2      # 2 places --%3E '0.01'%0A    _, digits, exp = Decimal(str(value)).quantize(q).as_tuple()%0A    result = %5B%5D%0A    digits = map(str, digits)%0A    build, next = result.append, digits.pop%0A    for i in range(2):%0A        build(next() if digits else '0')%0A    build('.')%0A    if not digits:%0A        build('0')%0A    i = 0%0A    while digits:%0A        build(next())%0A        i += 1%0A        if i == 3 and digits:%0A            i = 0%0A            build(',')%0A    build('$')%0A    return ''.join(reversed(result)
 )%0A

Fix money_format() filter so it isn't dependent on locale