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

Adam GROSZER agroszer.ll at gmail.com
Tue Aug 23 05:29:29 EDT 2011


Hello,

You forgot to paste interfaces.IMyObject definition.

On Tue, 23 Aug 2011 13:16:24 +0530 you wrote:
>
> 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.
>
>
>
>
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev at zope.org
> 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 )


-- 
Best regards,
  Adam GROSZER
--
Quote of the day:
Two men please God: who serves Him with all his heart because he knows 
Him; who seeks Him with all his heart because he knows Him not.
- Nikita Ivanovich Panin


More information about the Zope-Dev mailing list