[Zope] Access object inside a folder

Dieter Maurer dieter@handshake.de
Wed, 28 Jun 2000 20:59:35 +0200 (CEST)


Sin Hang Kin writes:
 > <dtml-in "_.getitem('tabledef').objectItems(['DTML Document'])" sort=id
 > mapping>
 >     <dtml-var "_['sequence-item']" html_quote>
 > </dtml-in>
 > 
 > Error Type: AttributeError
 > Error Value: __getitem__
This is as it should be:
  "objectItems" does not return a list of mapping objects.
  These objects do not have a mapping's "__getitem__"
  method. Therefore, you get the AttributeError.


 > <dtml-with tabledef>
 > <dtml-in "objectItems(['DTML Document'])" sort=id>
 >     <dtml-var "_['sequence-item']">
 > </dtml-in>
 > </dtml-with>
 > 
 > Error Type: AttributeError
 > Error Value: __call__
 > Traceback (innermost last):
 >   .....
 >   File C:\Program Files\Zope2\lib\python\DocumentTemplate\DT_With.py, line
 > 132, in render
 >     (Object: tabledef)
 > AttributeError: (see above)
That is very strange!

The error message (including traceback) tells that
Zope tried to access "tabledef.__call__". This
was impossible, because "tabledef" has no "__call__" attribute.

The strange thing: your DTML snipped does not contain
any place, where Zope must access "tabledef.__call__".
Both in the "dtml-with" as well as in "_['sequence-item']",
Zope will see, whether the objects are callable and if
so, it will call them.
It seems that "callable" returns true, but in fact one of
the objects is indeed not "callable".

 > If I add mapping:
 > <dtml-with tabledef>
 > <dtml-in "objectItems(['DTML Document'])" sort=id mapping>
 >     <dtml-var "_['sequence-item']">
 > </dtml-in>
 > </dtml-with>
 > 
 > Error Type: AttributeError
 > Error Value: __getitem__
That is the same as in the first example.


 > >  > Moreover, I would like to do the following:
 > >  >
 > >  > I have some properties of an object abc which have same name with the
 > object
 > >  > ids in the tabledef folder, I would also lookup the objects' properties
 > :
 > >  >
 > >  > <dtml-in propertyMap mapping>
 > >  >    <dtml-with tabledef.id>
 > > This will almost surely give a KeyError (tabledef.id).
 > > You must enclose it in "...".
 > >
 > >  >       <dtml-var help>
 > >  >      <dtml-var taborder>
 > >  >   </dtml-with>
 > >  > </dtml-in>
 > >
 > >  > Assume abc have a property address, then there should be a dtmldoc call
 > >  > address in tabledef, which have properties "help" and "tableorder". I
 > would
 > >  > like to retrieve them.
 > > I fear, I do not understand, what you want to do.
 > 
 > I have a folder call tabledef which use dtmldocument to keep some field
 > definition like its label, size, default value, help text etc. Which I would
 > like to generate the data entry form for it. The data will be stored as
 > object properties, so If I generate a edit form, then I should get the
 > property, lookup the field information in tabledef folder, and get the
 > label, size, information from there.
I am still not sure, what you are for.

But at least, I understand your partial problem: accessing the
content of a folder. I think I can help you with this.

When you look at the ObjectReference at URL:http://zdp.zope.org
(the Zope Documentation Portal), you will find that
"objectItems" returns a list of pairs "(id,subobject)".

"dtml-in" handles such list specially (-> dtml-in reference):
it calls the first component "sequence-key" and the second
"sequence-item".

The following DTML code works for me (Zope 2.1.6):

	<dtml-in "tabledef.objectItems(['DTML Method'])" sort=sequence-key>
	<h1><dtml-var sequence-key><-- the subobject's id--></h1>
	<dtml-var sequence-item> <-- the subobject itself, rendered-->
	</dtml-in>



Dieter