class CurrencyValidator(validators.FancyValidator):
"A validator to convert to Currency objects."
messages = {'amount': "Please enter a valid currency amount",
- 'precision': "Only two digits after the decimal, please"}
+ 'precision': "Only two digits after the decimal, please",
+ 'nonzero': "Please enter a non-zero amount"}
def _to_python(self, value, state):
try:
value, state)
else:
ret = dec.quantize(Decimal('1.00'))
- if ret != dec:
+ if ret == 0:
+ raise Invalid(self.message('nonzero', state),
+ value, state)
+ elif ret != dec:
raise Invalid(self.message('precision', state),
value, state)
else:
"""
return self.__mul__(other)
- def __str_no_dollar__(self):
- """
- Get to the formatted string without the dollar sign
- """
- return str(self).replace('$', '')
-
def __repr__(self):
return '%s("%s")' % (self.__class__.__name__, str(self))
def __str__(self):