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 ''

@@ -173,42 +173,31 @@
     
-Return value converted to a locale
+Format decimal value as
  cur
@@ -403,204 +403,574 @@
 dden
-%0A    symbol = getattr(settings, 'CURRENCY_SYMBOL', None)%0A    try:%0A        if symbol:%0A            return u%22%25s%25s%22 %25 (symbol, locale.format(%22%25.2f%22,%0A                                                   
+ as the version in system%0A    # locales if often not the desired one.%0A    try:%0A        symbol = getattr(settings, 'CURRENCY_SYMBOL', None)%0A        if symbol:%0A            # A custom currency symbol is specified.  Check to see if a%0A            # custom format is specified too - this allows the position of the%0A            # currency symbol to be controlled.%0A            format = getattr(%0A                settings, 'CURRENCY_FORMAT', u%22%25(symbol)s%25(value)s%22)%0A            return format %25 %7B%0A                'symbol': symbol,%0A                'value': locale.format(%22%25.2f%22,
  val
@@ -987,17 +987,17 @@
 ng=True)
-)
+%7D
 %0A       
@@ -1003,16 +1003,59 @@
   else:%0A
+            # Use locale's currency format%0A
         

Enhance currency filter to allow format string to be specified