[Grok-dev] Decimal validation error

Mats mats at ronin-group.org
Wed Sep 28 16:27:46 EST 2011


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>


More information about the Grok-dev mailing list