[Zope] getting zclass instance

John Hunter jdhunter@ace.bsd.uchicago.edu
Mon, 15 Jul 2002 12:16:57 -0500


I have a product Course that defines a ZClass Course and several other
Zclasses (Student, Submission, Section) etc...  A course might be
instantiated in a folder or at the root level, and can contain
sections which can contain students, which can contain submissions and
so on.

I want to have a Course method called get_course which returns the
Course instance, eg if I call

http://server:8080/folder/BioSci101/Section12/BillStudent/TermPaper/some_method_py
                            ^
                        the Course
                                      ^
                                    The Section
                                                 ^
                                             The Student

In some_method_py, which is a python script, if the above URL is the
context, I would like to be able to get the BioSci101 instance by
calling get_course_py, eg

folder = context.get_course_py()
for section in folder.objectValues('Section'):
   for student in section.objectValues('Student')

How can I get my hands on the Course instance?  I might imagine
traversing the parents, testing for isinstance of Course, or something
to that effect, but I suspect there is a more direct way.  And I do
not know what the python equivalent of the PARENTS list is, or if I
can use isinstance in python scripts.

Thanks,
John Hunter