[Zope3-dev] Finding context in a vocabulary

Peter Mayne PeterMayne at ap.spherion.com
Thu Sep 30 01:00:27 EDT 2004


I'm trying to emulate an Archetypes Reference field. I have an IRefto 
type that contains a reference to an ITarget type, which is a piece of 
cake to manipulate from a script, but the tricky part is allowing the 
user to edit it. What I want to do is present the user with a selection 
of ITarget types in the same folder as the IRefto type being edited.

I can follow the instructions in the handbook to create a vocabulary, 
but within the vocabulary class, I can't see how to ascertain where in 
the database my object is. The example in the handbook uses a container 
class, so the folder is implicit in the class, but in my case my 
vocabulary gets an instance of my non-container class, and I can't see 
how to discover the folder in which it exists. Besides, in the future, I 
may want to add sub-folders, peer folders, etc.

I've tried two different methods: using a Choice field (as in chapter 31 
of the book), and an Object field with a custom widget (chapter 15). Is 
there any aesthetic reason for preferring one over the other? I 
initially thought of the Object field because of the schema attribute 
restriction.

Thanks.

PJDM
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit



More information about the Zope3-dev mailing list