Re: [Zope3-Users] Internationalization, Widgets, and Currency

2006-05-09 Thread Gary Poster


On May 9, 2006, at 1:37 AM, Tom Dossis wrote:


David Johnson wrote:

I am trying to implement a currency input using a Float widget.


This wasn't your question, but, eek!  Currency should use a python  
decimal.Decimal, never a float.  I don't think we have  schema field  
and widget yet, but it would be trivial to add (the widget would  
effectively be identical, I believe).  Using floats for money is a  
bad idea


(a classic example:
 3.3
3.2998
 import decimal
 decimal.Decimal(3.3)
Decimal(3.3)
)

Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Internationalization, Widgets, and Currency

2006-05-08 Thread Tom Dossis

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):
  try:
  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
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users