Decimal validation error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Decimal validation error

Mats Nordgren
Grok/Zope/z3cform does not let you enter a decimal with more than 3
fractional numbers without getting a validation error.

I had this problem in Bluebream and solved it with a reimplemented
Data Coverter.  I'm trying to do the same in grok but have no luck in
making it work.

Any help appreciated.

-------------------------------------------------------------------------
#securities/price.py

class IPriceManager(interface.Interface):
    """A price manager"""

class IPrice(interface.Interface):
    """A price"""

    date = schema.Date(
        title = u'Date')

    price = FixedDecimal(
        title = u'Price')

--------------------------------------------------------------------------
#schema/__init__.py

class IFixedDecimal(IDecimal):
    """Fixed Decimal"""

class FixedDecimal(Decimal):
    grok.implements(IFixedDecimal)

class MyDecimalDataConverter(DecimalDataConverter):
    component.adapts(IFixedDecimal, IWidget)

    pattern = '#,##0.####'

    def toFieldValue(self, value):
        print '*'*100
        try:
            return self.formatter.parse(value, pattern=self.pattern)
        except NumberParseError, err:
            raise FormatterValidationError(self.errorMessage, value)

-------------------------------------------------------------------------
#overrides.zcml

<configure
  xmlns="http://namespaces.zope.org/zope">

  <adapter
    factory="iport.schema.MyDecimalDataConverter" />
</configure>

-------------------------------------------------------------------------
#configure.zcml

<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:grok="http://namespaces.zope.org/grok">
  <include package="grok" />
  <includeDependencies package="." />
  <grok:grok package="." />
  <includeOverrides file="overrides.zcml" />
</configure>
_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev