[BlueBream] bluebream Digest, Vol 9, Issue 4

Jonah Crawford jonah at microgridsystems.com
Sun Sep 5 12:24:35 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks Thierry,

I'm assuming that root = getParents(context)[-2] in your example below would traverse to a persistent folder with the terms a client adds to it.

Also are you saying that Vocabularies remember or persist their context so that it does not need to be passed one when it is called ?

Thanks again!

Jonah

On Sep 5, 2010, at 9:00 AM, bluebream-request at zope.org wrote:



> Hi,
> 
> I think you should better use a vocabulary to define such a dynamic
> list of values, as a vocabulary can be dynamic and have a context.
> 
> Something like that:
> 
>  from zope.dublincore.interfaces import IZopeDublinCore as IDC
>  from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
> 
>  class GroupsVocabulary(SimpleVocabulary):
> 
>    classProvides(IVocabularyFactory)
> 
>    def __init__(self, context):
>      root = getParents(context)[-2]
>      terms = [SimpleTerm(name,name,title)
>               for name,title in ((zapi.getName(item),IDC(item).title)
>                                  for item in root.values())]
>      super(GroupsVocabulary,self).__init__(terms)
> 
> Registering is done like that in ZCML:
> 
>  <utility
>    name="groupids"
>    component=".GroupsVocabulary" />
> 
> or in Python code in the same way ; and the interface is modified as
> follow:
> 
>  class INeedTheGroupListing(IContainer):
>    groups = List(value_type=Choice(title=u'Client generated groups',
>                                    vocabulary='groupids'),
>                  required=True)
> 
> 
> Hope this helps,
> Thierry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iQIcBAEBAgAGBQJMg8RDAAoJEDXlFJ3rri4KpKYQALkqJSHPobXrj6BRXjFbrJOL
A8UUaTVzxw9ov8NDxtDVDOLvUXaxcEerTcMW8gk/LD9RWLt5Yr2pSQHoaxvR3ajw
U6andWF4KgAZTWklktFlkc7Mlrt72w5paboEACgn/R0KBxcGbektv+QesvvjUoXK
iV9Auo8YudfEItZiZUEM4MxQZ0Qlw/BATucSpcpWOpVkmDnZ5L8M74nKwbuEVEY1
US1BYsfSbBEPUZmDf1ofh1QaqGSLMu6GLVpoBXKGd/sxqkGep6/TX+m1dvn7DRB6
E/Q0Dyjdzgj4x2qqBC+qUxtjTuZW22hQrgAcpQfCVGNXnW8EYnooWtgs78xp8OTv
RBhXMhk9YDZwxRlMESV4VKsuSRcS49N4jjaJxVj2xgfDvz5fT9Bb8TBRFZ6sgTCl
FL0EO0zgdyvy6tCTuX41YNY2JegOWqMkuV7uOeZtD9YeyIpCKvlGbKTP4HKqPViy
qkVrSHoX5z3eQteY9cTw1EI1BEGL5iTyjpRygUtv7ijliZtMyaA09P0ws4M3ZiMe
RJTKVRd4JB2dxWFvmFrxYx1OTQV675Cuwe3Wi9yRDD/1wU77L0tinziC80eFO/QU
0MsqnRfJlFYYppTVuDftQFpczhnPn4WmFWpV5o8MpUshmXkBPYLhYbAC8Tmg50Ac
eKFTIHq6i6Ipt4hk/e+f
=E28P
-----END PGP SIGNATURE-----


More information about the bluebream mailing list