[Zope] Re: Missunderstanding of DTML Methods and acquisition?

Jonothan Farr jfarr@real.com
Mon, 13 Mar 2000 13:51:50 -0800


> What I'm most confused about right now is when it is necessary to pass
> the client and namespace and when you can omit it.  I'm also very unclear
> as to just what the 'client' is, especially since most of the examples
> I've seen involve passing in None for the client.


I found the source to String.__call__ (in DocumentTemplate/DT_String.py) very
enlightening. This is the same __call__ method that DTMLMethod and DTMLDocument
inherit.


    def __call__(self,client=None,mapping={},**kw):
        '''\
        Generate a document from a document template.

        The document will be generated by inserting values into the
        format string specified when the document template was
        created.  Values are inserted using standard python named
        string formats.

        The optional argument 'client' is used to specify a object
        containing values to be looked up.  Values will be looked up
        using getattr, so inheritence of values is supported.  Note
        that names beginning with '_' will not be looked up from the
        client.

        The optional argument, 'mapping' is used to specify a mapping
        object containing values to be inserted.

        Values to be inserted may also be specified using keyword
        arguments.

        Values will be inserted from one of several sources.  The
        sources, in the order in which they are consulted, are:

          o  Keyword arguments,

          o  The 'client' argument,

          o  The 'mapping' argument,

          o  The keyword arguments provided when the object was
             created, and

          o  The 'mapping' argument provided when the template was
             created.

        '''

You can see that __call__ with no arguments uses defaults of None and {} for
client and mapping, so essentially the template has nowhere to look up
attributes. This is why you must pass these explicitly. Apparently you can also
pass a mapping and keywords to the constructor but I don't think this is
possible from the management interface.

More ZZen is to be found in DocumentTemplate/DT_Util.py. This module contains
the expression evaluation machinery, as well as the code to the special
namespace variable, '_'.

-jfarr

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi! I'm a signature virus.
Copy me into your .sig to join the fun!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~