Re: [Zope] How to access id and title of document calling standard_html_header
Tim Hicks writes:
I have a standard_html_header that is inserted into Zclasses. These Zclasses have properties including meta_author ... In standard_html_header, I use code such as <dtml-var meta_author> ... This works fine and the properties of the *zclass* are inserted. However, if I put <dtml-var id> into the standard_html_header, I get the id of standard_html_header, *not* of the zclass. When I do this, I get the id of the Z class instance. It should be impossible to get the id of the *standard_html_header*, if this header is a DTML *method* (rather than document) as you told us in a different message.
Because we see different things, we need to describe carefully, what we do. Apparently, we do not do the same. I have a folder-like ZClass, say ZC, and an instance of this class, say ZI. ZC has a method, say M, using "standard_html_header". "standard_html_header" is a DMTL method (!) rendering "id". When I open "ZI/M", "standard_html_header" renders "ZI", i.e. ZI's id. The same happens, if "standard_html_header" is not in ZI but a ZC method. Now, it is your turn to describe precisely, what you are doing. Dieter
----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Tim Hicks" <tim.hicks@iname.com> Cc: <zope@zope.org> Sent: Monday, September 04, 2000 7:48 PM Subject: Re: [Zope] How to access id and title of document calling standard_html_header
Tim Hicks writes:
I have a standard_html_header that is inserted into Zclasses. These Zclasses have properties including meta_author ... In standard_html_header, I use code such as <dtml-var meta_author> ... This works fine and the properties of the *zclass* are inserted. However, if I put <dtml-var id> into the standard_html_header, I get the id of standard_html_header, *not* of the zclass. When I do this, I get the id of the Z class instance. It should be impossible to get the id of the *standard_html_header*, if this header is a DTML *method* (rather than document) as you told us in a different message.
Because we see different things, we need to describe carefully, what we do. Apparently, we do not do the same.
I have a folder-like ZClass, say ZC, and an instance of this class, say ZI. ZC has a method, say M, using "standard_html_header". "standard_html_header" is a DMTL method (!) rendering "id". When I open "ZI/M", "standard_html_header" renders "ZI", i.e. ZI's id.
The same happens, if "standard_html_header" is not in ZI but a ZC method.
Now, it is your turn to describe precisely, what you are doing.
OK, I think that I am perhaps misusing zclasses then. Here is what I have. I have a Folder that was created by using the 'Add new item' menu within Zope. This folder is called 'Site'. I have a Zclass called 'theatre_class' that has "Base classes ZObject, _ZClass_for_CatalogAware, _ZClass_for_DTMLDocument". I have set the zclass to have the following properties by creating a 'theatre_class_property' property sheet for it: head_title meta_author meta_description ... amongst others. Within the Folder 'Site', I have standard_html_header dtml-method that is an edited version of the default one that is found in the root folder of a Zope instance (if that is the right term). This standard_html_header uses things code such as this: <title><dtml-var head_title></title> <META NAME="description" CONTENT="<dtml-var meta_description>"> <META NAME="author" CONTENT="<dtml-var meta_author>"> When I use the standard_html_header in an instance of a zclass, the appropriate property of the zclass is indeed inserted into it. See below. Zclass instance has code such as: <dtml-var standard_html_header> <h1>This is an instance of my Theatre Zclass</h1> <dtml-var standard_html_footer> However, if I try to put <dtml-var id> into the standard_html_header, I get nothing, and if I use <dtml-var document_id>, I get 'standard_html_header' inserted into the document. I hope I have made it clear what I am doing. It is certainly becoming clear to me that I have got the wrong end of the stick a little with this. Thanks for your help. tim
Dieter
Tim Hicks writes:
OK, I think that I am perhaps misusing zclasses then. Here is what I have. No you did not.
I have a Folder that was created by using the 'Add new item' menu within Zope. This folder is called 'Site'.
I have a Zclass called 'theatre_class' that has "Base classes ZObject, _ZClass_for_CatalogAware, _ZClass_for_DTMLDocument"....
Within the Folder 'Site', I have standard_html_header dtml-method ... However, if I try to put <dtml-var id> into the standard_html_header, I get nothing...
I analysed your problem (in Zope 2.1.6). It is *NOT* a problem of "standard_html_header". Instead, it is a ZCLass problem. The id of a ZInstance created as you described it returns "<string>". The browser shows this as "empty" because it is a tag it does not understand and therefore ignores. You see it, though, when you look at the HTML source. The reason for this strange id lies in a mismatch between your ZClass, more precisely its __init__ method, and the content of REQUEST: For some reason, your ZClass uses "DocumentTemplate.DT_String.__init__" as constructor. "DocumentTemplate.DT_String" defines a "id" function and lets it return the value of the "__init__" parameter "__name__". The default for "__name__" is, you guess it, "'<string>'". "ZClass.createInObjectManager" constructs the ZInstance. If the instance has a 'id', it takes this id and ignores the 'id' passed as parameter. Thus, you get a ZInstance with this strange id. I am convinced, this is a ZClass bug. I think, that the bug results from the fact, that the constructor for a ZCLass deriving from DTML Document used "__name__" as "id" replacement. The analysis provides a workaround for you. In your ZClass constructor, add <dtml-call "REQUEST.set('__name__',REQUEST['id'])"> before the <dtml-with "<yourClass>.createInObjectManager(REQUEST['id'],REQUEST)"> Now, after I did some work for you, I have some tasks for you: * check, whether the bug is in Zope 2.2.1, too * if this turns out to be the case, file a bug report into the collector. Dieter
----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Tim Hicks" <tim@sitefusion.co.uk> Cc: <zope@zope.org> Sent: Tuesday, September 05, 2000 9:44 PM Subject: ZClass Bug (was: Re: [Zope] How to access id and title of document calling standard_html_header)
Tim Hicks writes:
OK, I think that I am perhaps misusing zclasses then. Here is what I have. No you did not.
That's a relief.
I have a Folder that was created by using the 'Add new item' menu within Zope. This folder is called 'Site'.
I have a Zclass called 'theatre_class' that has "Base classes ZObject, _ZClass_for_CatalogAware, _ZClass_for_DTMLDocument"....
Within the Folder 'Site', I have standard_html_header dtml-method ... However, if I try to put <dtml-var id> into the standard_html_header, I get nothing...
I analysed your problem (in Zope 2.1.6). It is *NOT* a problem of "standard_html_header". Instead, it is a ZCLass problem.
OK.
The id of a ZInstance created as you described it returns "<string>". The browser shows this as "empty" because it is a tag it does not understand and therefore ignores. You see it, though, when you look at the HTML source.
Yup, I'm with you on that.
The reason for this strange id lies in a mismatch between your ZClass, more precisely its __init__ method, and the content of REQUEST: For some reason, your ZClass uses "DocumentTemplate.DT_String.__init__" as constructor. "DocumentTemplate.DT_String" defines a "id" function and lets it return the value of the "__init__" parameter "__name__". The default for "__name__" is, you guess it, "'<string>'".
You are losing me a bit with the "__init__", "DocumentTemplate.DT_String" and "__name__" (I'm afraid my Python is limited, to say the least!). I do see the results of <string> being the default value though ;-).
"ZClass.createInObjectManager" constructs the ZInstance. If the instance has a 'id', it takes this id and ignores the 'id' passed as parameter.
Thus, you get a ZInstance with this strange id.
I think I'm with you there.
I am convinced, this is a ZClass bug. I think, that the bug results from the fact, that the constructor for a ZCLass deriving from DTML Document used "__name__" as "id" replacement.
The analysis provides a workaround for you. In your ZClass constructor, add <dtml-call "REQUEST.set('__name__',REQUEST['id'])"> before the <dtml-with
"<yourClass>.createInObjectManager(REQUEST['id'],REQUEST)">
Great. I presume that this will only work for all *new* instances of this class however! I don't suppose you know of a way of remaking all 44 instances of this Zclass I have using this adjusted constructor? I have tried (see below), but I think I come up against the same '<string>' problem that I'm actually trying to counteract! <dtml-in Catalog> <dtml-call "REQUEST.set('sequence-item',REQUEST['id'])"> <dtml-with "theatre_class.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-call "propertysheets.theatre_class_property.manage_editProperties(REQUEST)"
<dtml-call "manage_edit(REQUEST)"> </dtml-with> </dtml-in> Anyway, I guess this is a different problem again really isn't it? I think for now, it will be easier to use my less elegant workaround of giving the zclass another property called 'counter_id' * that is the same as the actual id. I know that this works, and it won't take as long as remaking all the instances again... I don't have the strength for that I don't think. I'll definitely file away your fix for future reference though. Thanks very much.
Now, after I did some work for you, I have some tasks for you:
* check, whether the bug is in Zope 2.2.1, too
Yes, it does. I have now found this to occur in 2.1.6, 2.2.0 and 2.2.1.
* if this turns out to be the case, file a bug report into the collector.
Right, I have done that, hopefully satisfactorily! Hope you don't mind, I used 'extensive' quotes from your reply... no point in using my words to confuse the issue! Thanks very much Dieter, you've been a MASSIVE help. tim
Dieter
Tim Hicks writes:
.... I presume that this will only work for all *new* instances of this class however! I don't suppose you know of a way of remaking all 44 instances of this Zclass I have using this adjusted constructor? I have tried (see below), but I think I come up against the same '<string>' problem that I'm actually trying to counteract! I do -- in principle :-)
When you rename an instance, the instance gets a correct id. Now, all operations you can do through the web, can be done programmatically. Either by an external program based on "ZPublisher.Client" or by an internal script. Look in the searchable archive to find a post from me that explains how to determine the necessary function calls from the management source (if you do not know it already). An alternative is to look in the Zope object reference (--> zdp.zope.org). You may use "ZopeFind" to locate all your ZClass objects in order to rename them. Details are left for you. Dieter
----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Tim Hicks" <tim@sitefusion.co.uk> Cc: <zope@zope.org> Sent: Tuesday, September 05, 2000 9:44 PM Subject: ZClass Bug (was: Re: [Zope] How to access id and title of document calling standard_html_header) <snip>
The analysis provides a workaround for you. In your ZClass constructor, add <dtml-call "REQUEST.set('__name__',REQUEST['id'])"> before the <dtml-with
"<yourClass>.createInObjectManager(REQUEST['id'],REQUEST)">
<snip> Dieter, I tried using the code that you suggested above, but I get the following error from Zope 2.2.1 <snipped traceback> File C:\PROGRA~1\Zope221\lib\python\DocumentTemplate\DT_With.py, line 133, in render (Object: theatre_class.createInObjectManager(REQUEST['id'], REQUEST)) File C:\PROGRA~1\Zope221\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval (Object: theatre_class.createInObjectManager(REQUEST['id'], REQUEST)) (Info: REQUEST) File <string>, line 0, in ? NameError: theatre_class It would seem that <string> is still raising its head. Any ideas? tim
participants (2)
-
Dieter Maurer -
Tim Hicks