[Zope] dtml-var AND dtml-tree

Dieter Maurer dieter@handshake.de
Fri, 13 Apr 2001 11:32:19 +0200 (CEST)


Hi Danny!

Danny William Adair writes:
 > ....
 > As soon as somebody tells me how to solve this part (accept python
 > expressions and evaluate them) I will put the patch in the Collector.
Sorry, "branches_expr" was probably not the best example, I could have
given.

Following is how it is done in "Products.MIMETools.MIMETag"
for "type/type_expr":

  in "__init__":

            if has_key('type_expr'):
                if has_key('type'):
                    raise ParseError, _tm('type and type_expr given', 'mime')
                args['type_expr']=VSEval.Eval(args['type_expr'], expr_globals)

  in "render":

            if has_key('type_expr'): t=a['type_expr'].eval(md)
            else: t=a['type']

Slight adjustments will be necessary in "TreeTag"....

 > meantime I *wanted to* wrap it up as some kind of "hotfix product", so no
 > one has to mess with patching the python sources.
 > 
 > Unfortunately... TreeDisplay's __init__.py - which in return calls
 > TreeTag.py's Tree.__init__.py - gets called before my product's __init__,
 > and I don't know how to override an __init__ (I think it's impossible, and
 > it would make sense, too). Sorry. Any hints? Or is it really impossible?
You do not need to override the "__init__".

  You override functions in the module or class.

  In your "__init__.py", you have:

    from TreeDisplay import TreeTag # now the module "TreeTag" is loaded
                                    # ready to be patched

    def module_func(...):
      ....
    TreeTag.module_func= module_func # overrides "module_func" in module
                                     # "TreeTag"

    def class_func(self,....):
      ....
    TreeTag.TreeTag.class_func= class_func
                                     # overrides "class_func" in class
				     # "TreeTag.TreeTag"

Dieter