dtml access to "container" within zclass
hi all, is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? in a python script, this is exposed as the "container" variable (assuming the binding is set, of course), but in a dtml method i can't figure out how to make it happen. specifically, i have a dtml method called "detail_html" and a python script called "detail", both in a zclass that does NOT actually live in the zope object file system (it's a loginmanager user object). i'd like to have the detail_html method work like this: <dtml-with "detail()"> ... ... </dtml-with> such that the detail python script returns a namespace which populates the dtml method. nothing i do seems to work, though... "detail" doesn't exist in the global namespace, nor in "_". my workaround is to have the python script call the dtml method and then return it, like so: ... ... return container.detail_html(context, subdict) where "subdict" is a dictionary of values that are then exposed in the dtml method's namespace. this works, but it's less than ideal, because it needlessly obfuscates the code, IMO. i don't want my front-end designers to have to be digging through complicated python code to figure out which dtml methods are being used... i'd much rather have them just see the dtml code, which would quietly suck in the data from the python script using <dtml-with>. am i missing something obvious? -r
Ra writes:
is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? When called from ZPublisher (i.e. the Web), it should run in the context of this Z instance, i.e. the instance is at the top of the DTML namespace. You can (under these conditions) use its "this" method to get the instance itself.
Dieter
Dieter Maurer wrote:
Ra writes:
is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? When called from ZPublisher (i.e. the Web), it should run in the context of this Z instance, i.e. the instance is at the top of the DTML namespace. You can (under these conditions) use its "this" method to get the instance itself.
Alas, "this" isn't working; I get "global name 'this' is not defined". The problem seems to be that the ZClass instance _isn't_ at the top of my DTML namespace. If it were, I would just be able to refer to my other methods directly, using <dtml-with>, like I want to. It may be a bug in LoginManager's LoginUser... my ZClass is subclassing a python base class wrapper, which is in turn subclassing LoginUser. I have another ZClass, subclassing a different python base class. This base class in turn subclasses DataSkin and OFS.Folder.Folder. The problem does not happen in this second ZClass. -r
ra@burningman.com writes:
Dieter Maurer wrote:
Ra writes:
is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? When called from ZPublisher (i.e. the Web), it should run in the context of this Z instance, i.e. the instance is at the top of the DTML namespace. You can (under these conditions) use its "this" method to get the instance itself.
Alas, "this" isn't working; I get "global name 'this' is not defined". Looks like the DTML Method is not called correctly (apparently, nothing on its namespace has an acquisition context).
How is th DTML Method activated? Via ZPublisher? Explicitely? Dieter
Dieter Maurer wrote:
ra@burningman.com writes:
Dieter Maurer wrote:
Ra writes:
is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? When called from ZPublisher (i.e. the Web), it should run in the context of this Z instance, i.e. the instance is at the top of the DTML namespace. You can (under these conditions) use its "this" method to get the instance itself.
Alas, "this" isn't working; I get "global name 'this' is not defined". Looks like the DTML Method is not called correctly (apparently, nothing on its namespace has an acquisition context).
Yep, this was it.
How is th DTML Method activated? Via ZPublisher? Explicitely?
I've got a dtml-method called "member_detail_html" which calls the dtml-method "detail_html" within the user object. "member_detail_html" originally contained the following: ------------- <dtml-var header> <dtml-if membername> <dtml-var "acl_users.getItem(membername).detail_html()"> <dtml-else> <dtml-var "_.SecurityGetUser().detail_html()"> </dtml-if> <dtml-var footer> -------------- I changed "member_detail_html" like so: -------------- <dtml-var header> <dtml-if membername> <dtml-let userobj="acl_users.getItem(membername)"> <dtml-var "userobj.detail_html(userobj, REQUEST)"> <dtml-let> <dtml-else> <dtml-var "_.SecurityGetUser().detail_html(_.SecurityGetUser(), REQUEST)"> </dtml-if> <dtml-var footer> --------------- and it is now working. I'm not 100% certain I've chosen the right parameters to pass in, though... my best guess is that the first parameter is supposed to be the "this()" object (i.e. the top of the called method's namespace stack) and the second parameter should be the REQUEST, if needed. Is this correct? Thanks for your help! -r
ra@burningman.com wrote:
Dieter Maurer wrote:
ra@burningman.com writes:
Dieter Maurer wrote:
Ra writes:
is there any way to gain access to an instance of a zclass from a dtml method that is within that zclass? When called from ZPublisher (i.e. the Web), it should run in the context of this Z instance, i.e. the instance is at the top of the DTML namespace. You can (under these conditions) use its "this" method to get the instance itself.
Alas, "this" isn't working; I get "global name 'this' is not defined". Looks like the DTML Method is not called correctly (apparently, nothing on its namespace has an acquisition context).
Yep, this was it.
How is th DTML Method activated? Via ZPublisher? Explicitely?
I've got a dtml-method called "member_detail_html" which calls the dtml-method "detail_html" within the user object. "member_detail_html" originally contained the following:
------------- <dtml-var header>
<dtml-if membername> <dtml-var "acl_users.getItem(membername).detail_html()"> <dtml-else> <dtml-var "_.SecurityGetUser().detail_html()"> </dtml-if>
<dtml-var footer> --------------
I changed "member_detail_html" like so:
-------------- <dtml-var header>
<dtml-if membername> <dtml-let userobj="acl_users.getItem(membername)"> <dtml-var "userobj.detail_html(userobj, REQUEST)"> <dtml-let> <dtml-else> <dtml-var "_.SecurityGetUser().detail_html(_.SecurityGetUser(), REQUEST)"> </dtml-if>
<dtml-var footer> ---------------
and it is now working. I'm not 100% certain I've chosen the right parameters to pass in, though... my best guess is that the first parameter is supposed to be the "this()" object (i.e. the top of the called method's namespace stack) and the second parameter should be the REQUEST, if needed. Is this correct?
Oh, never mind on this last question. I simplified even further... the method now looks like this: ------------- <dtml-var header> <dtml-if membername> <dtml-with "acl_users.getItem(membername)"> <dtml-var detail_html> <dtml-with> <dtml-else> <dtml-with "_.SecurityGetUser()"> <dtml-var detail_html> </dtml-with> </dtml-if> <dtml-var footer> -------------- which is how I should have done it in the first place. Thanks again for pointing me in the right direction! -r
participants (3)
-
Dieter Maurer -
Ra -
ra@burningman.com