Keeping a Variable's Value: This SHOULD Be Easy
OOPS! Correction... ...but apparently it's not. If I were writing this in PHP: <html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html> ...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
On Tue, Oct 30, 2001 at 11:38:37AM -0800, Ben Ocean wrote:
...but apparently it's not. If I were writing this in PHP:
<? x = int mt_rand(0,9); echo x ?> <? echo x ?>
...but apparently DTML *does* forget.
I assume you're setting your random variable value inside a double-quoted expression along the lines of <dtml-var "foo=_.random()"> or similar. If so, remember that every invocation of the double-quotes is a new Python call, with its own (mostly read-only) copy of the available namespace. Unless you modify the existing namespace via something like <dtml-call "REQUEST.set(foo,_.random())">, foo simply won't be available later in the object. I may completely misunderstand the question, but I think that's what you're asking. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
Ben Ocean wrote:
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
You forgot to wrap your code in <dtml-let pointless_sarcasm="no">. HTH. Seriously, dtml-let is your ticket; do the assignment in the opening tag and it will be accessible to everything inside the block. If dtml-let doesn't fit your code, do <dtml-var expr="REQUEST.set('name', value)">. -- Matt Behrens <matt.behrens@kohler.com> System Analyst, Baker Furniture
On Tue, 2001-10-30 at 14:38, Ben Ocean wrote:
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
if you put the result in the REQUEST object you can reference it other places. <dtml-call expr="REQUEST.set('x', _.random.randint(0,9))"> my random number is = <dtml-var x> .... my random number is still = <dtml-var x> -- Tom Jenkins Development InfoStructure http://www.devis.com
This SHOULD... Unfortunately the ways to keep a python object's value while processing DTML are "buzzy": 1/ Use the REQUEST mapping object <dtml-call "REQUEST.set('foo', something)"> HTML/raw text/XML blah blah <dtml-var "REQUEST['foo']> 2/ Get HappySession or another user session management product to keep the value between two requests In both cases, unfortunately, you can use only one python expression to initialize the value HTH --Gilles ----- Original Message ----- From: "Ben Ocean" <zope@thewebsons.com> To: <zope@zope.org> Sent: Tuesday, October 30, 2001 8:38 PM Subject: [Zope] Keeping a Variable's Value: This SHOULD Be Easy
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
At 10:59 PM 10/30/01 +0100, you wrote:
2/ Get HappySession or another user session management product to keep the value between two requests
I tried this (since REQUEST didn't fill the request) and used this line: <dtml-call "SESSION.set('foo', something)"> where *something* was a dtml method that executed the evaluation of a python expression. Now, whereas REQUEST *was* able to execute said expression and HappySession *was* happy substituting a simple string, HappySession was not happy evaluating the python expression :( Any more ideas? TIA, BenO
----- Original Message ----- From: "Ben Ocean" <zope@thewebsons.com> To: <zope@zope.org> Sent: Tuesday, October 30, 2001 8:38 PM Subject: [Zope] Keeping a Variable's Value: This SHOULD Be Easy
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi Ben, How about this? <dtml-call "SESSION.set('foo', something(_.None,_))"> I still don't understand it fully even though it was explained to me a few times, but I think its something to do with expressions always having to satisfy that the method must return something (self). Paul Zwarts -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Ben Ocean Sent: Wednesday, October 31, 2001 11:17 AM To: Gilles Lenfant Cc: zope@zope.org Subject: [Zope] Unhappy HappySession (was Keeping a Variable's Value: This SHOULD Be Easy) At 10:59 PM 10/30/01 +0100, you wrote:
2/ Get HappySession or another user session management product to keep the value between two requests
I tried this (since REQUEST didn't fill the request) and used this line: <dtml-call "SESSION.set('foo', something)"> where *something* was a dtml method that executed the evaluation of a python expression. Now, whereas REQUEST *was* able to execute said expression and HappySession *was* happy substituting a simple string, HappySession was not happy evaluating the python expression :( Any more ideas? TIA, BenO
----- Original Message ----- From: "Ben Ocean" <zope@thewebsons.com> To: <zope@zope.org> Sent: Tuesday, October 30, 2001 8:38 PM Subject: [Zope] Keeping a Variable's Value: This SHOULD Be Easy
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Ah, that worked! Bliss at last! BenO At 01:11 PM 10/31/01 +0100, you wrote:
Hi Ben,
How about this?
<dtml-call "SESSION.set('foo', something(_.None,_))">
I still don't understand it fully even though it was explained to me a few times, but I think its something to do with expressions always having to satisfy that the method must return something (self).
Paul Zwarts
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Ben Ocean Sent: Wednesday, October 31, 2001 11:17 AM To: Gilles Lenfant Cc: zope@zope.org Subject: [Zope] Unhappy HappySession (was Keeping a Variable's Value: This SHOULD Be Easy)
At 10:59 PM 10/30/01 +0100, you wrote:
2/ Get HappySession or another user session management product to keep the value between two requests
I tried this (since REQUEST didn't fill the request) and used this line: <dtml-call "SESSION.set('foo', something)"> where *something* was a dtml method that executed the evaluation of a python expression. Now, whereas REQUEST *was* able to execute said expression and HappySession *was* happy substituting a simple string, HappySession was not happy evaluating the python expression :(
Any more ideas? TIA, BenO
----- Original Message ----- From: "Ben Ocean" <zope@thewebsons.com> To: <zope@zope.org> Sent: Tuesday, October 30, 2001 8:38 PM Subject: [Zope] Keeping a Variable's Value: This SHOULD Be Easy
OOPS! Correction...
...but apparently it's not. If I were writing this in PHP:
<html><body> Okay, boys and girls! Let's open the magic box and generate a random number! (applause)<br and drum roll> <? x = int mt_rand(0,9); echo x ?><br, strike up the band> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of horror> <? echo x ?><br, strike up the band again> Oh, of course! How could I forget!<br, fade to black> </body></html>
...but apparently DTML *does* forget. Call that daggone variable more than once and you have to run the formula that generates a random digit! Bam! Variable's gone. Is there no way around this? Please help... BenO
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (6)
-
Behrens Matt - Grand Rapids -
Ben Ocean -
Gilles Lenfant -
Mike Renfro -
Paul Zwarts -
Tom Jenkins