""" Stay DRY, import intcomma """
from django.contrib.humanize.templatetags.humanize import intcomma


class USDecimalHumanizedInput(forms.TextInput):
  def __init__(self, initial=None, *args, **kwargs):
    super(USDecimalHumanizedInput, self).__init__(*args, **kwargs)
  
  def render(self, name, value, attrs=None):
    value = intcomma(value)
    return super(USDecimalHumanizedInput, self).render(name, value, attrs)


class USDecimalHumanizedField(forms.DecimalField):
  """
  Use this as a drop-in replacement for forms.DecimalField()
  """
  widget = USDecimalHumanizedInput
  
  def clean(self, value):
    value = value.replace(',','')
    super(USDecimalHumanizedField, self).clean(value)
    return value