[Zope-dev] Decimal validation error.

Mats Nordgren mats at ronin-group.org
Wed Feb 17 15:37:17 EST 2010


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 at 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 at qwer.tk
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope-dev/attachments/20100217/c7cce560/attachment.html 


More information about the Zope-Dev mailing list