[Zope-dev] getting size of zope.schema.List from a view in bluebream

Joshua Immanuel josh at hipro.co.in
Tue Aug 23 03:46:24 EDT 2011


Hello all,
	While trying to get the length of zope.schema.List field in a view
(like this: len(self.context.list_field) I get the following error

        ForbiddenAttribute: ('__len__', [])
        
Even though my zcml configuration for that class is defined as below

  <class class=".app.MyObject">

    <require
        permission="zope.Public"
        interface=".interfaces.IMyObject"
        />

    <require
        permission="zope.Public"
        set_schema=".interfaces.IMyObject"
        />
  </class>

I still get the above error. To circumvent this issue, I added a method
in the interface like say 'getListSize()' which has the following
implementation

        class MyObject(persistent.Persistent):
            implements(IMyObject)
        
            name = u''
            list_field = PersistentList()
            ...
        
            def getListSize(self):
                return len(self.list_field)
        
This solves my issue. However, I am curious to know whether is this the
only solution available to the above issue. Am I going in the right
direction?

Please guide me.

-- 
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20110823/066257ed/attachment.bin 


More information about the Zope-Dev mailing list