More REQUEST.set() not incrementing
Hi again, No response to my first distress call, so I thought maybe some more details would help. When I insert some print commands, the assigned "counter" (u_*) variables exist, but are reported as being equal to zero (0). So, it appears that the original assignment is "taking". Except that when I look at all of the variables by printing <dtml-var REQUEST>, the same variables appear as being equal to one (1), so it seeems like the incrementing is happening. Except that, the number never increases beyond one, so that it seems that what appeared to be incrementing was really just re-setting the variable to zero plus 1 (0 + 1), as if each pass through the loop is refreshing the values to the original assignment. So, one might conclude that the _ variables are not persistent, or are too persistent, depending on how you look at it. The assorted ways I've tried to assign and retrieve these variable, e.g. in : <dtml-var u_all> <dtml-var "u_all"> <dtml-var _[u_all]> <dtml-var _["u_all"]> <dtml-var "_[u_all]"> <dtml-var "_['u_all']"> Thanks for looking at this silly thing, Jerry S. <dtml-with "REQUEST.set('z_t', _.string.split(_.str(ZopeTime()))[0])"> <dtml-let u_all="_.string.atoi('0')" u_logged="_.string.atoi('0')" u_today="_.string.atoi('0')"> <dtml-var u_all> <dtml-var u_logged> <dtml-var u_today><br> REQUEST = <dtml-var REQUEST> <dtml-in count_users_logged> <dtml-call "REQUEST.set('u_all',_.int(u_all)+1)"> users_with_access = <dtml-var u_all> <br> <dtml-if logged_on> <dtml-call "REQUEST.set('u_logged',_.int(u_logged)+1)"> users_logged_ever = <dtml-var u_logged> <br> <dtml-if "z_t==_.string.split(_.str(_.DateTime(logged_on)))[0]"> <dtml-call "REQUEST.set('u_today',_.int(u_today)+1)"> users_logged_today = <dtml-var u_today> <br> </dtml-if> </dtml-if> </dtml-in> users_with_access = <dtml-var u_all> <br> users_logged_ever = <dtml-var u_logged> <br> users_logged_today = <dtml-var u_today> <br> REQUEST = <dtml-var REQUEST></dtml-let> </dtml-with>
Hi, ----- Original Message ----- From: <Jerry.Spicklemire@IFLYATA.COM> To: <zope@zope.org> Sent: Tuesday, January 11, 2000 4:49 PM Subject: [Zope] More REQUEST.set() not incrementing
So, one might conclude that the _ variables are not persistent, or are too persistent, depending on how you look at it.
This is the correct conclusion. If you want to store info like this in the ZODB, you need to make a property. (Folders, ZClasses and DTML Documents can all have properties). Let's say you wanted to count how many people access a given Folder. You could add a property (count) to that Folder, and then put the following in your standard_html_header: <dtml-call "manage_changeProperties({'count': count+1})"> Note: this creates a new transaction for every page view on the Folder, and your Data.fs will grow. (Not by much, but it will grow) There are a couple counter products up on zope.org, I think, that may give you some tips. HTH, Kevin
On Tue, 11 Jan 2000 Jerry.Spicklemire@IFLYATA.COM wrote:
Hi again,
No response to my first distress call, so I thought maybe some more details would help.
When I insert some print commands, the assigned "counter" (u_*) variables exist, but are reported as being equal to zero (0). So, it appears that the original assignment is "taking".
Except that when I look at all of the variables by printing <dtml-var REQUEST>, the same variables appear as being equal to one (1), so it seeems like the incrementing is happening.
Except that, the number never increases beyond one, so that it seems that what appeared to be incrementing was really just re-setting the variable to zero plus 1 (0 + 1), as if each pass through the loop is refreshing the values to the original assignment.
I tried this: <dtml-let i="0"> <dtml-in "_.range(100"> <dtml-call "REQUEST.set('i', i + 1)"> <dtml-var i> </dtml-in> </dtml-let> and got: 0 0 0 ... 0 Then, I changed it to: <dtml-call "REQUEST.set('i', 0)"> <dtml-in "_.range(100)"> <dtml-call "REQUEST.set('i', i + 1)"> <dtml-var i> </dtml-in> and got: 1 2 3 ... 100 I haven't had a chance to peer into the code and see how let is implemented, yet, but it is my guess that dtml-let is defining the variable in the *local DTML namespace*, and REQUEST.set('i', i + 1) is setting the value of 'i' in *the request* to the local value of i plus 1 each time through the loop, thus always outputting 1. Initializing i with a simple <dtml-call "REQUEST.set('i', 0)"> makes the inside of the loop uniformly access 'i' in the REQUEST. Of course, I could be wrong. :)
Thanks for looking at this silly thing,
Hope this helps!
Jerry S.
--Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
This should work: <dtml-call "REQUEST.set('i',0)"> <dtml-in "_.range(100)"> <dtml-let j="i+1" <dtml-call "REQUEST.set('i', j)"> </dtml-let> <dtml-var i> </dtml-in> I have never had consistent success using formulas in REQUEST.set __________________________________________________________________ Jim Sanford . Database Engineer / \ / Accelerated Technology, Inc. / / 720 Oak Circle Drive East / / \ Mobile, AL 36609 / / \ Voice: 334-661-5770 fax: 334-661-5788 / \ E-Mail: jsanford@atinucleus.com Web: http://www.atinucleus.com Source Code, No Royalties, Any CPU...It just make sense ! __________________________________________________________________ ----- Original Message ----- From: Jeff K. Hoffman <jeff@goingv.com> To: <Jerry.Spicklemire@iflyata.com> Cc: <zope@zope.org> Sent: Tuesday, January 11, 2000 4:32 PM Subject: Re: [Zope] More REQUEST.set() not incrementing On Tue, 11 Jan 2000 Jerry.Spicklemire@IFLYATA.COM wrote:
Hi again,
No response to my first distress call, so I thought maybe some more details would help.
When I insert some print commands, the assigned "counter" (u_*) variables exist, but are reported as being equal to zero (0). So, it appears that the original assignment is "taking".
Except that when I look at all of the variables by printing <dtml-var REQUEST>, the same variables appear as being equal to one (1), so it seeems like the incrementing is happening.
Except that, the number never increases beyond one, so that it seems that what appeared to be incrementing was really just re-setting the variable to zero plus 1 (0 + 1), as if each pass through the loop is refreshing the values to the original assignment.
I tried this: <dtml-let i="0"> <dtml-in "_.range(100"> <dtml-call "REQUEST.set('i', i + 1)"> <dtml-var i> </dtml-in> </dtml-let> and got: 0 0 0 ... 0 Then, I changed it to: <dtml-call "REQUEST.set('i', 0)"> <dtml-in "_.range(100)"> <dtml-call "REQUEST.set('i', i + 1)"> <dtml-var i> </dtml-in> and got: 1 2 3 ... 100 I haven't had a chance to peer into the code and see how let is implemented, yet, but it is my guess that dtml-let is defining the variable in the *local DTML namespace*, and REQUEST.set('i', i + 1) is setting the value of 'i' in *the request* to the local value of i plus 1 each time through the loop, thus always outputting 1. Initializing i with a simple <dtml-call "REQUEST.set('i', 0)"> makes the inside of the loop uniformly access 'i' in the REQUEST. Of course, I could be wrong. :)
Thanks for looking at this silly thing,
Hope this helps!
Jerry S.
--Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/ _______________________________________________ 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 (4)
-
Jeff K. Hoffman -
Jerry.Spicklemire@IFLYATA.COM -
Jim Sanford -
Kevin Dangoor