I have a DTML method from which I want to answer a dictionary. It looks something like this: <dtml-return "{'foo':'bar', 'biff':'boom'}"> I want to be able to use this information in two different ways. First, I want to be able to get a list of keys from the dictionary. Second, I want to be able to get a list of values. I could easily do this in Python, but I'm sure there must be a simple way to do this in DTML. I tried something like: <dtml-return "_['dictionaryVariableName'].keys()"> but that didn't work. I did notice that if I just used "_['dictionaryVariableName']" I actually got the keys. Basically I'm trying to create a system by which a user can enter a full string and an abbreviation for the string. I want to be able to produce a list of the full strings, and I want to be able to produce a list of the abbreviations. Any help would be appreciated. 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>
to be able to get a list of values. I could easily do this in Python, but I'm sure there must be a simple way to do this in DTML. I tried something like:
<dtml-return "_['dictionaryVariableName'].keys()">
but that didn't work. I did notice that if I just used "_['dictionaryVariableName']" I actually got the keys.
That should have worked. You should be able to manipulate your dictionary just as you would expect. What happened when you tried it? What do you get from <dtml-var expr="_['dictionaryVariableName']">? Cheers, Evan @ 4-am & digicool
At 04:04 PM 3/1/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
to be able to get a list of values. I could easily do this in Python, but I'm sure there must be a simple way to do this in DTML. I tried something like:
<dtml-return "_['dictionaryVariableName'].keys()">
but that didn't work. I did notice that if I just used "_['dictionaryVariableName']" I actually got the keys.
That should have worked. You should be able to manipulate your dictionary just as you would expect. What happened when you tried it? What do you get from <dtml-var expr="_['dictionaryVariableName']">?
I get an "AttributeError" on "keys". 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>
<dtml-return "_['dictionaryVariableName'].keys()">
I get an "AttributeError" on "keys".
Hmm. Somehow you aren't getting a dictionary, then. It's hard to tell from just what you've posted where it's going astray. Are you dtml-return-ing a literal dict as in your initial posting? How is dictionaryVariableName set? Cheers, Evan @ 4-am & digicool
At 09:27 PM 3/1/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
<dtml-return "_['dictionaryVariableName'].keys()">
I get an "AttributeError" on "keys".
Hmm. Somehow you aren't getting a dictionary, then. It's hard to tell from just what you've posted where it's going astray. Are you dtml-return-ing a literal dict as in your initial posting? How is dictionaryVariableName set?
Here's what I've got. First, I have a DTMLMethod named creditCardsAccepted which is defined as follows: <dtml-return " { 'Visa':'V', 'Mastercard':'MC', 'American Express':'AE', 'Diners Club':'DC', 'Discover':'DS', 'Carte Blanche:'CB', 'Japanese Credit Bureau':'JCB', 'Transmedia':'T' }"> I then have a method called creditCardSelections which is defined as follows: <dtml-return "creditCardsAccepted.keys()"> (I also tried <dtml-return "_['creditCardsAccepted'].keys()">) When I try to "view" my creditCardSelections, I get the attribute error on 'keys'. 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>
Here's what I've got. First, I have a DTMLMethod named creditCardsAccepted
I then have a method called creditCardSelections which is defined as follows:
<dtml-return "creditCardsAccepted.keys()">
Try <dtml-return "creditCardsAccepted().keys()"> Cheers, Evan @ 4-am & digicool
At 08:21 AM 3/2/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
Here's what I've got. First, I have a DTMLMethod named creditCardsAccepted
I then have a method called creditCardSelections which is defined as follows:
<dtml-return "creditCardsAccepted.keys()">
Try <dtml-return "creditCardsAccepted().keys()">
Just tried that, same results (keys error). (BTW, there was a typo in my message describing the dictionary I was returning. The typo existed only in the e-mail, not in the actual code) James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
At 08:21 AM 3/2/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
Here's what I've got. First, I have a DTMLMethod named creditCardsAccepted
I then have a method called creditCardSelections which is defined as follows:
<dtml-return "creditCardsAccepted.keys()">
Try <dtml-return "creditCardsAccepted().keys()">
Followup, I just realized that I had two definitions of "creditCardsAccepted". One was defined inside my ZClass, and one was defined in the folder containing the ZClass. The one in the container was just answering a list. When I changed that one to answer a dictionary things worked. I then simply deleted the DTMLMethod in the containing folder and now I get a name error. Now I'm really confused. After deleting the higher level method, I now have the creditCardsAccepted and the creditCardSelections both in the same folder. It seems, however, that the creditCardSelections cannot see the sibling method. I'm clearly overlooking something. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
From: "James W. Howe" <jwh@allencreek.com>
At 08:21 AM 3/2/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
Here's what I've got. First, I have a DTMLMethod named creditCardsAccepted
I then have a method called creditCardSelections which is defined as follows:
<dtml-return "creditCardsAccepted.keys()">
Try <dtml-return "creditCardsAccepted().keys()">
Followup,
I just realized that I had two definitions of "creditCardsAccepted". One was defined inside my ZClass, and one was defined in the folder containing the ZClass. The one in the container was just answering a list. When I changed that one to answer a dictionary things worked. I then simply deleted the DTMLMethod in the containing folder and now I get a name error. Now I'm really confused. After deleting the higher level method, I now have the creditCardsAccepted and the creditCardSelections both in the same folder. It seems, however, that the creditCardSelections cannot see the sibling method.
I'm clearly overlooking something.
You'll have to call your DTML Method in a special way. When caling a DTML object with <dtml-var name=DTMLMethodOrObject> this is automatically taken care of. but when using it in the above way, you have to do this by hand: <dtml-in "creditCardSelections(_, _.None, *other arguments*)"> You now pass in the namespace as well, so your DTML knows how to access other Zope Objects. This _will_ change in the future, BTW, this will be automated for various reasons. You then won't have to think about all this anymore. Have alook at the following How-To, and espcecially the list referrenced at the bottom of it: http://www.zope.org/Members/Pam/DTMLScripting They will introduce you to the more advanced ideas of DTML scripting. Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | The Open Source Web Application Server ---------------------------------------------
participants (3)
-
Evan Simpson -
James W. Howe -
Martijn Pieters