Re: Decimal validation error.

Hermann Himmelbauer <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
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


-- 
[email protected]
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
_______________________________________________
Zope-Dev maillist  -  [email protected]
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 )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.