Advanced DTML Question
I'm trying to write a DTMLMethod which will write out a list of data items found from a catalog, sorted in alphabetical order. This is easy. Basically I do something like this: <dtml-in "Catalog(meta_type='foo')" sort=someAttribute> <dtml-with "Catalog.getobject(data_record_id_)"> <dtml-var objvar1><dtml-var objvar2> ... </dtml-with> </dtml-in> I've got this working, no problem. Now, since the list of these items might be somewhat long, I want to build a simple index at the top of the page and use page anchors to get to key points on the page. Basically I'm going to display the alphabet and when the user clicks on a letter, the page should scroll somewhere in the vicinity of an item which starts with that letter. To that end, what I would like to do is have some code inside of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know how to code this up. It seems like maybe that at least some of this should be done at the Python level but I'm not quite sure how to split up the functionality. Has anybody done anything similar who would be willing to give me some advice as to the best way to go about solving this problem? Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know
Quick, possibly misleading idea: if you can give your Catalog entries a brain class with a function "anchorGroup" which returns the first letter of the entry, then you can use <dtml-if sequence-first-anchorGroup><a name="&dtml-anchorGroup;"></a></dtml-if> Cheers, Evan @ 4-am & digicool
At 04:01 PM 3/1/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know
Quick, possibly misleading idea: if you can give your Catalog entries a brain class with a function "anchorGroup" which returns the first letter of the entry, then you can use <dtml-if sequence-first-anchorGroup><a name="&dtml-anchorGroup;"></a></dtml-if>
"Brain Class?" Could you explain that a bit? It so happens that the objects I'm getting out of my catalog are instances of a ZClass that I created. That ZClass inherits from a basically empty Python base class. Is this what you mean by a "brain class"? If so, are you saying that I should just define a method in my Python code which does the "anchorGroup" thing? Even if this isn't what you meant, I think I like the idea that you are proposing. I just need to make sure that I actually understand what you are suggesting. Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
"Brain Class?" Could you explain that a bit? It so happens that the objects I'm getting out of my catalog are instances of a ZClass that I created. That ZClass inherits from a basically empty Python base class. Is this what you mean by a "brain class"?
I think so. A "brain" in obscure Zope parlance is a class used to enhance a raw tabular record, such as a ZSQLMethod or ZCatalog returns.
If so, are you saying that I should just define a method in my Python code which does the "anchorGroup" thing?
Exactly! Cheers, Evan @ 4-am & digicool
At 04:01 PM 3/1/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know
Quick, possibly misleading idea: if you can give your Catalog entries a brain class with a function "anchorGroup" which returns the first letter of the entry, then you can use <dtml-if sequence-first-anchorGroup><a name="&dtml-anchorGroup;"></a></dtml-if>
I've tried to do something like you suggested, but it doesn't seem to work. I'm probably not doing things quite correctly. I've added a "getAnchorCharacter" method to my ZClass which correctly answers the character I want to use as an anchor. I've tested this and know that it works. I tried using "<dtml-if sequence-first-getAnchorCharacter> ...", but got no result. Could you explain a bit more about how something like "sequence-first-xxx" works? I haven't found any information on this form of a dtml-in variable. Perhaps I'm just misunderstanding your solution. In thinking about this solution, it seems that if I'm inside of a dtml-in iterating over entries in a Catalog, the objects known to the "dtml-in" aren't instances of my ZClass, but instances of some catalogging wrapper for my ZClass. Therefore, it would seem that my getAnchorCharacter method wouldn't be accessible from within the dtml-in, but only from within a dtml-with which sets the object to be the object referenced by the catalog entry. Can you clarify all this? Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
I've tried to do something like you suggested, but it doesn't seem to work. I'm probably not doing things quite correctly. I've added a "getAnchorCharacter" method to my ZClass which correctly answers the character I want to use as an anchor. I've tested this and know that it works. I tried using "<dtml-if sequence-first-getAnchorCharacter> ...", but got no result. Could you explain a bit more about how something like "sequence-first-xxx" works? I haven't found any information on this form of a dtml-in variable. Perhaps I'm just misunderstanding your solution.
Check the Grouping Variables subsection of http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.8.html I did give you the wrong syntax; it's <dtml-if first-getAnchorCharacter>, with no "sequence-".
In thinking about this solution, it seems that if I'm inside of a dtml-in iterating over entries in a Catalog, the objects known to the "dtml-in" aren't instances of my ZClass, but instances of some catalogging wrapper for my ZClass. Therefore, it would seem that my getAnchorCharacter method wouldn't be accessible from within the dtml-in, but only from within a dtml-with which sets the object to be the object referenced by the catalog entry.
I misunderstood you. The catalog wrapper is the "brain" which needs to have the getAnchorCharacter method. But... Suppose you add getAnchorCharacter as a catalogued meta_type in your Catalog? I think that would work. Cheers, Evan @ 4-am & digicool
At 11:15 AM 3/2/00 -0600, Evan Simpson wrote:
I misunderstood you. The catalog wrapper is the "brain" which needs to have the getAnchorCharacter method. But... Suppose you add getAnchorCharacter as a catalogued meta_type in your Catalog? I think that would work.
I'll give that a try. If I wanted to add a method to the catalog wrapper, is there a non-invasive way to do this or would I have to modify some standard Zope code to work differently? Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
"James W. Howe" wrote:
I'm trying to write a DTMLMethod which will write out a list of data items found from a catalog, sorted in alphabetical order. This is easy. Basically I do something like this:
<dtml-in "Catalog(meta_type='foo')" sort=someAttribute> <dtml-with "Catalog.getobject(data_record_id_)"> <dtml-var objvar1><dtml-var objvar2> ... </dtml-with> </dtml-in>
I've got this working, no problem. Now, since the list of these items might be somewhat long, I want to build a simple index at the top of the page and use page anchors to get to key points on the page. Basically I'm going to display the alphabet and when the user clicks on a letter, the page should scroll somewhere in the vicinity of an item which starts with that letter. To that end, what I would like to do is have some code inside of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know how to code this up. It seems like maybe that at least some of this should be done at the Python level but I'm not quite sure how to split up the functionality.
Has anybody done anything similar who would be willing to give me some advice as to the best way to go about solving this problem?
Have you tried the How-To: -- In flying I have learned that carelessness and overconfidence are usually far more dangerous than deliberately accepted risks. -- Wilbur Wright in a letter to his father, September 1900
At 07:03 PM 03/01/2000 -0700, Bill Anderson wrote:
"James W. Howe" wrote:
I'm trying to write a DTMLMethod which will write out a list of data items found from a catalog, sorted in alphabetical order. [...]
Has anybody done anything similar who would be willing to give me some advice as to the best way to go about solving this problem?
Have you tried the How-To:
Do you have a particular one in mind? I looked, but it's entirely possible that I missed one which might be appropriate. James Howe internet: mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
"James W. Howe" wrote:
I'm trying to write a DTMLMethod which will write out a list of data items found from a catalog, sorted in alphabetical order. This is easy. Basically I do something like this:
<dtml-in "Catalog(meta_type='foo')" sort=someAttribute> <dtml-with "Catalog.getobject(data_record_id_)"> <dtml-var objvar1><dtml-var objvar2> ... </dtml-with> </dtml-in>
I've got this working, no problem. Now, since the list of these items might be somewhat long, I want to build a simple index at the top of the page and use page anchors to get to key points on the page. Basically I'm going to display the alphabet and when the user clicks on a letter, the page should scroll somewhere in the vicinity of an item which starts with that letter. To that end, what I would like to do is have some code inside of my dtml-in loop which gets the first letter from the current entry, checks to see if an anchor for that letter has been written, if not, a new anchor tag is inserted into the stream. My problem is I don't really know how to code this up. It seems like maybe that at least some of this should be done at the Python level but I'm not quite sure how to split up the functionality.
Has anybody done anything similar who would be willing to give me some advice as to the best way to go about solving this problem?
My email window dies suddenly, before I could write what I intedned ... looks like it sent itself waaay too early. Sorry. Anyway, have you tried the batch processing instructions at http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.8.5.html They should give you some insight as to how to get the first letter. You may then be able to set a temp variable, called CurrentAnchor, for example, that contains the last letter that was used to set an anchor. Testing agaimst the CurrentAnchor, you should be able to set (if not the same), or continue (if the same). Unfortunately, ZCatalog apparently doesn't do reg-ex searches yet. Otherwise, I'd say create your links a alink to a page that looked for thins that started with that letter. Alternatively, you could look at the howto, and give a range of letter, say a-e, f-j, etc. and just use the batch processing capabilities in DTML. :) Just some ideas. -- In flying I have learned that carelessness and overconfidence are usually far more dangerous than deliberately accepted risks. -- Wilbur Wright in a letter to his father, September 1900
participants (3)
-
Bill Anderson -
Evan Simpson -
James W. Howe