I have an interface with a decimal field. It validates fine for 1,2 and 3 fractions but if I enter a decimal with 4 fractions I get validation error "The entered value is not a valid decimal literal." I'm using the pypi release of bluebream and z3c.form 2.3.2. Mats
Seems a plain vanilla install of bluebream validates decimals fine with zope.app.form. Does z3c.form validate decimal fields or is that delegated to zope.schema? On Wed, Feb 10, 2010 at 8:27 AM, Mats Nordgren <mats@ronin-group.org> wrote:
I have an interface with a decimal field. It validates fine for 1,2 and 3 fractions but if I enter a decimal with 4 fractions I get validation error "The entered value is not a valid decimal literal."
I'm using the pypi release of bluebream and z3c.form 2.3.2.
Mats
On Wed, Feb 10, 2010 at 12:25:51PM -0800, Mats Nordgren wrote:
Seems a plain vanilla install of bluebream validates decimals fine with zope.app.form. Does z3c.form validate decimal fields or is that delegated to zope.schema?
I also hit this, AFAIKR z3c.form delegates it to zope.i18n. We worked around this (no proper solution I'm afraid) by overriding the default DataConverter in z3c.form.
On Wed, Feb 10, 2010 at 8:27 AM, Mats Nordgren <mats@ronin-group.org> wrote:
I have an interface with a decimal field. It validates fine for 1,2 and 3 fractions but if I enter a decimal with 4 fractions I get validation error "The entered value is not a valid decimal literal."
I'm using the pypi release of bluebream and z3c.form 2.3.2.
Mats
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )
-- Brian Sutherland
Am Mittwoch 10 Februar 2010 17:27:09 schrieb Mats Nordgren:
I have an interface with a decimal field. It validates fine for 1,2 and 3 fractions but if I enter a decimal with 4 fractions I get validation error "The entered value is not a valid decimal literal."
I'm using the pypi release of bluebream and z3c.form 2.3.2.
I remember that one - quite cumbersome. Try something like this: # You should use the following interface for your forms: class IMyDecimal(IDecimal): """Specify custom decimal interface""" # Now create a custom data converter class MyDecimalDataConverter(BaseDecimalDataConverter): """Adapt decimal data converter""" adapts(IMyDecimal, IWidget) # The amount of '#' after the '.' outlines the no. of decimal places pattern = '#,##0.####' # And specify in overrides.zcml <adapter factory="mymodule.MyDecimalDataConverter" /> This works for me. Best Regards, Hermann -- hermann@qwer.tk GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
Thanks Hermann, This still does not work for me. The pattern = '#,##0.####' seems to have no effect on the converter. Perhaps I'm doing something wrong, I'm posting my setup below. This most certainly have to be a bug in the system if you can't put 1.2345 into a decimal field, no? If so is there a bug tracker for z3c.form where I can post this and get it fixed? #interfaces.py class IFixedDecimal(IDecimal): """Fixed decimal field.""" class FixedDecimal(schema.Decimal): interface.implements( IFixedDecimal) class ITaxLot(interface.Interface): """A tax lot""" quantity = FixedDecimal( title = u'Quantity', required = True) #holding.py class MyDecimalDataConverter(DecimalDataConverter): """Adapt decimal data converter""" adapts(IFixedDecimal, IWidget) # The amount of '#' after the '.' outlines the no. of decimal places pattern = '#,##0.####' #configure.zcml <includeOverrides file="overrides.zcml" /> #overrides.zcml <adapter factory=".holding.MyDecimalDataConverter" /> On Thu, Feb 11, 2010 at 3:21 AM, Hermann Himmelbauer <dusty@qwer.tk> wrote:
Am Mittwoch 10 Februar 2010 17:27:09 schrieb Mats Nordgren:
I have an interface with a decimal field. It validates fine for 1,2 and 3 fractions but if I enter a decimal with 4 fractions I get validation error "The entered value is not a valid decimal literal."
I'm using the pypi release of bluebream and z3c.form 2.3.2.
I remember that one - quite cumbersome. Try something like this:
# You should use the following interface for your forms: class IMyDecimal(IDecimal): """Specify custom decimal interface"""
# Now create a custom data converter class MyDecimalDataConverter(BaseDecimalDataConverter): """Adapt decimal data converter""" adapts(IMyDecimal, IWidget) # The amount of '#' after the '.' outlines the no. of decimal places pattern = '#,##0.####'
# And specify in overrides.zcml <adapter factory="mymodule.MyDecimalDataConverter" />
This works for me.
Best Regards, Hermann
-- hermann@qwer.tk GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
Am Mittwoch 17 Februar 2010 21:37:17 schrieb Mats Nordgren:
Thanks Hermann,
This still does not work for me. The pattern = '#,##0.####' seems to have no effect on the converter. Perhaps I'm doing something wrong, I'm posting my setup below.
This most certainly have to be a bug in the system if you can't put 1.2345 into a decimal field, no? If so is there a bug tracker for z3c.form where I can post this and get it fixed?
#interfaces.py class IFixedDecimal(IDecimal): """Fixed decimal field."""
class FixedDecimal(schema.Decimal): interface.implements( IFixedDecimal)
class ITaxLot(interface.Interface): """A tax lot"""
quantity = FixedDecimal( title = u'Quantity', required = True)
#holding.py class MyDecimalDataConverter(DecimalDataConverter): """Adapt decimal data converter""" adapts(IFixedDecimal, IWidget)
# The amount of '#' after the '.' outlines the no. of decimal places pattern = '#,##0.####'
#configure.zcml
<includeOverrides file="overrides.zcml" />
#overrides.zcml
<adapter factory=".holding.MyDecimalDataConverter" />
Ah, I forgot the method, try to add something like this to your converter: def toFieldValue(self, value): try: return self.formatter.parse(value, pattern=self.pattern) except zope.i18n.format.NumberParseError, err: raise FormatterValidationError(self.errorMessage, value) I'd furthermore suggest to add some debugging information into this method to make sure that it is actually called. Best Regards, Hermann -- hermann@qwer.tk GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
participants (3)
-
Brian Sutherland -
Hermann Himmelbauer -
Mats Nordgren