David Johnson wrote:
I am trying to implement a currency input using a Float widget. However, the widget is populated with a strange character, and when saving the data that strange character causes problems. I do not see a Currency widget. What is the proper internationalization technique in regards to currency and widgets?

If I just use the float widget without the locale, the numbers are displayed without the trailing zeros that are standard, although it otherwise works fine. For example, US $1.20 is displayed as 1.2.

You could try a customised FloatWidget (or TextWidget) to allow you to control the display and input value formats, a e.g.

  class CurrencyWidget(TextWidget):

      def _toFieldValue(self, input):
              return float(input) # convert to currency object
          except ValueError, v:
              raise ConversionError(_("Invalid currency format .."), v)

      def _getFormValue(self):
          currency = super(CurrencyWidget, self)._getFormValue()
          if currency:
              return '$0.2f' % currency # display currency

Zope3-users mailing list

Reply via email to