[Zope3-Users] TAL and Decimals

Michael Howitz mh at gocept.com
Wed Apr 5 02:35:38 EDT 2006


Am Dienstag, den 04.04.2006, 11:24 -0500 schrieb David Johnson:
> I am reading a decimal field from a database and trying to display it
> in a page template. What is the TAL to do this? 
> Among other things, I’ve tried:
> <div tal:replace="python: u'%f' % (item.price)" />
> 
> Which generates the follow exception:
> ForbiddenAttribute: ('__float__', Decimal("0.00"))
>
> I’ve also tried the simple:
> $<div tal:replace="item/price" />
> 
>  Which displays:
> $<security proxied decimal.Decimal instance at 0x41d76694>

Hi,

in current Zope versions python decimals are security proxied.
(See also http://www.zope.org/Collectors/Zope3-dev/543 )

I think a better solution than the one described in the bug is the
following:

Write an interface IDecimal which includes alle the mehtods you want to
access in views and page tempates.

Put the following into your configure.zcml:

<class class="decimal.Decimal">
    <implements interface=".interfaces.IDecimal" />
    <allow interface=".interfaces.IDecimal" />
</class>

It declares that the class decimal.Decimal implements your IDecimal
interface and that there are no security restrictions on the interface.

HTH,
 mac





More information about the Zope3-users mailing list