How do I call DTML Method which name is stored in a variable
Hi, Thanks to Evan Simpson, I learned a method can be called in the following way: <dtml-var expr="_.render(FetchObj(_.None, _,fetchStr='hie/dee/hoe').id)"> Suppose the name of the method is stored in a variable. How do I invoke the method? -- Carlos Henrique Bauer
the simple anwser for Carlos Henrique Bauer, <dtml-var "_[variable]"> I was doing to post this pure DTML response to "String to object ID" (it was not too complex... 3 lines, no count </dtml-..>), but I ran into a nice triple checking the path length because of DTML's 'with' construct. (same deal with direct addressing). Know I'm wonder why it can't be fixed, why can't <dtml-var "_['folder.subfolder']._['object'].id"> just work???? I looked at the source code, AFAIK its only the security '_' that stops it. (I'm no expert!) Summery: a single path level, i.e. no periods in the name "myfolder" used in 'dtml-with' needs to be fetched with "_['string_without_dots_in_it']" or "_.getitem('string',flag)" flag defaults to 0, which does not call a callable object. set to 1 if you want it to call them. Where as a string with periods "myfolder.subfolder.stuff" needs: "'string.with.dots.in.it'" or e.g. <dtml-with "_.string.join(path_with_object[:-1],'.')"> The last check in the triple was if the path is only the object... no path. OK an example: I can use this to access objects from a Catalog search, as long as I know it doesn't have the above problem with DTML addressing... (you could replace getpath(stuff) with a absolute_url splitter to make it even more complex) <dtml-let path_with_object="_.string.split(getpath(data_record_id_)[1:],'/')"> <dtml-with "_.string.join(path_with_object[:-1],'.')"> <dtml-var "_[path_with_object[-1]].id"></dtml-with></dtml-let> The above is faster than getobject(data_record_id_,REQUEST) by ~40% :') its fast I like it. :) Having fun with DTML ;) David, tone..
Carlos Henrique Bauer wrote:
Thanks to Evan Simpson, I learned a method can be called in the following way: <dtml-var expr="_.render(FetchObj(_.None, _,fetchStr='hie/dee/hoe').id)">
Suppose the name of the method is stored in a variable. How do I invoke the method?
Hmm. Did you mean your variable (let's call it 'v') contains 'hie/dee/hoe', or 'id'? If the former, <dtml-var expr="_.render(FetchObj(_.None, _,fetchStr=v).id)"> If the latter, <dtml-with expr="FetchObj(_.None, _,fetchStr='hie/dee/hoe')"><dtml-var expr="_[v]"></dtml-with> is probably best. Frankly, I hate jumping through these hoops, and I'll probably extend dtml-var one of these days so we can just write: <dtml-var id of=hie/dee/hoe> or <dtml-var expr="v" of="objectname"> Cheers, Evan @ 4-am
Hi all, I have an odd question about acquistion, it has to do with acquiring anything that starts with an underscore. Can anyone explain this to me. (I understand w/ inheritance of names that start with one underscore the name is changed to privitize the variable, but this seems different) Here is an example of what I am talking about: class C(ExtensionClass.Base): __color__='red' class A(Acquisition.Implicit):pass a=A() c=C() c.a=A() c.a.__color__ Traceback (innermost last): File "<stdin>" line1 in ? AttributeError:__color__ but if we take off the underscore, the results are as we expect, class C(ExtensionClass.Base): color='red' class A(Acquisition.Implicit):pass a=A() c=C() c.a=A() c.a.__color__ 'red' This question comes out of a program that I am writing where I want the subjobjects acquire the __ac_permissions__ of the containing folder. Thanks, Scott
scott kaplan wrote:
Hi all, I have an odd question about acquistion, it has to do with acquiring anything that starts with an underscore. Can anyone explain this to me. (I understand w/ inheritance of names that start with one underscore the name is changed to privitize the variable, but this seems different)
It is. Acquisition doesn't work on names starting with an underscore; They're considered private. Cheers, Evan @ 4-am
Evan Simpson wrote:
scott kaplan wrote:
Hi all, I have an odd question about acquistion, it has to do with acquiring anything that starts with an underscore. Can anyone explain this to me. (I understand w/ inheritance of names that start with one underscore the name is changed to privitize the variable, but this seems different)
It is. Acquisition doesn't work on names starting with an underscore; They're considered private.
However, you can acquire them with the aq_acquire method: x.aq_acquire('_spam') You can't do this from DTML however. Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
On Fri, 10 Dec 1999, you wrote:
Carlos Henrique Bauer wrote:
Thanks to Evan Simpson, I learned a method can be called in the following way: <dtml-var expr="_.render(FetchObj(_.None, _,fetchStr='hie/dee/hoe').id)">
Suppose the name of the method is stored in a variable. How do I invoke the method?
Hmm. Did you mean your variable (let's call it 'v') contains 'hie/dee/hoe', or 'id'?
No. The variable contains the name of the method I want to call and which must receive some arguments and return a value, for example: <dtml-call "REQUEST.set('doc', fetchObj(_.None, _, fetchStr=docPath))"> <dtml-call "REQUEST.set('metaMethod', _.string.join(_.string.split(_.render(doc.meta_type)[0:])''))"> <dtml-call "REQUEST.set('metaMethod', _.string.join([metaMethod, 'GetMetaInfo' ], ''))"> If docPath points to a DTMLDocument, metaMethod becomes "DTMLDocumentGetMetaInfo". I'm trying to do something like this (it didn't worked for me): <dtml-let something="_[metaMethod].(_.None, _,fetchStr=docPath)"> </dtml-let> Best regards, -- Carlos Henrique Bauer
Carlos Henrique Bauer wrote:
On Fri, 10 Dec 1999, you wrote:
Carlos Henrique Bauer wrote:
Thanks to Evan Simpson, I learned a method can be called in the following way: <dtml-var expr="_.render(FetchObj(_.None, _,fetchStr='hie/dee/hoe').id)">
Suppose the name of the method is stored in a variable. How do I invoke the method?
Hmm. Did you mean your variable (let's call it 'v') contains 'hie/dee/hoe', or 'id'?
No. The variable contains the name of the method I want to call and which must receive some arguments and return a value, for example:
<dtml-call "REQUEST.set('doc', fetchObj(_.None, _, fetchStr=docPath))"> <dtml-call "REQUEST.set('metaMethod', _.string.join(_.string.split(_.render(doc.meta_type)[0:])''))"> <dtml-call "REQUEST.set('metaMethod', _.string.join([metaMethod, 'GetMetaInfo' ], ''))">
If docPath points to a DTMLDocument, metaMethod becomes "DTMLDocumentGetMetaInfo".
I'm trying to do something like this (it didn't worked for me):
<dtml-let something="_[metaMethod].(_.None, _,fetchStr=docPath)"> </dtml-let>
I'm not sure I really follow this, but if you want to fetch a method and then call it, this should work: <dtml-let something="FetchObj(_.None, _,fetchStr=metaMethod)(_.None, _, args...)"> Cheers, Evan @ 4-am
On Mon, 13 Dec 1999, you wrote:
I'm not sure I really follow this, but if you want to fetch a method and then call it, this should work:
<dtml-let something="FetchObj(_.None, _,fetchStr=metaMethod)(_.None, _, args...)">
Unfortunately, it doesn't work. The method returned by FetchObj is called but does not receive or does not have access to the args. Zope returns a KeyError. Best regards, -- Carlos Henrique Bauer
participants (5)
-
Carlos Henrique Bauer -
David Kankiewicz -
Evan Simpson -
Jim Fulton -
scott kaplan