Ejemplo n.º 1
0
 def render(self, context):
     if self.var:
         val = self.var.resolve(context)
         locale = Locale.objects.get(name=val)
     else:
         locale = get_locale()
     context.push()
     context[self.name] = locale
     output = self.nodelist.render(context)
     context.pop()
     return output
Ejemplo n.º 2
0
def currency(value, locale_name=None):
    if locale_name:
        locale = Locale.objects.get(name=locale_name)
    else:
        try:
            locale = get_locale(value)
        except Locale.DoesNotExist:
            if hasattr(value, 'currency') and hasattr(value, 'amount'):
                if hasattr(value.currency, 'code'):
                    return u'%s %s' % (value.currency.code, value.amount)
                return u'%s %s' % (value.currency, value.amount)
            return value
    return locale.currency(value)