[Zope] Subject: [Zope] More REQUEST.set not incrementing SUCCESS!
Tres Seaver
tseaver@palladion.com
Wed, 12 Jan 2000 19:56:58 -0600
Jerry.Spicklemire@IFLYATA.COM wrote:
>
> Jeff Hoffman suggested the following code, that's quite a bit cleaner than
> what I came up with, and it also works quite well.
>
> <dtml-call "REQUEST.set('z_t', _.string.split(_.str(ZopeTime()))[0])">
> <dtml-call "REQUEST.set('u_all', 0)">
> <dtml-call "REQUEST.set('u_logged', 0)">
> <dtml-call "REQUEST.set('u_today', 0)">
> <dtml-call "REQUEST.set('u_not', 0)">
>
> <dtml-var u_all> <dtml-var u_logged> <dtml-var u_today><br>
>
> <dtml-in count_users_logged>
> <dtml-call "REQUEST.set('u_all', u_all + 1)">
> <dtml-if logged_on>
> <dtml-call "REQUEST.set('u_logged', u_logged + 1)">
> <dtml-if "_['z_t']==_.string.split(_.str(_.DateTime(logged_on)))[0]">
> <dtml-call "REQUEST.set('u_today', u_today + 1)">
> </dtml-if>
> <dtml-else>
> <dtml-call "REQUEST.set('u_not', u_not + 1)">
> </dtml-if>
> </dtml-in>
>
> I'm a bit mystified that the only detectable difference between this version
> and *many* that I tried without success looks to be the spaces between
> objects and keywords in expressions, along with the complete absence of
> <dtml-let>.
>
> e.g <dtml-call "REQUEST.set('u_logged', u_logged + 1)">
>
> vs. <dtml-call "REQUEST.set('u_logged',u_logged+1)">
>
> I've looked at lot's of code samples that have no spaces, and have seen
> enough error messages to think very hard about random spaces in expressions.
> This is a good example of how code lore (superstition) gets proliferated,
> but it's hard to argue with working examples.
>
> Thanks again, to Jeff, Jim, Pavlos, et. al.
As the giant says to the Sicilian, "I don't think that word means what you think
it means," or in this case, that tag.
The <dtml-let> tag is really just syntactic sugar for <dtml-with "_.namespace(
..." )> -- it constructs a new, *readonly* namespace, populated with the values
you supply in the tag's attributes, and pushes that namespace on top of the DTML
namespace stack. This new namespace softly and silently vanishes away at the
</dtml-in>, leaving no trace that it ever existed. You should also be aware
that this let namespace interacts oddly with calls to other DTML methods -- in
fact, I haven't quite figured out how to make them play nice together.
Phil Eby, who contributed the let tag, has an extension, <dtml-set>, which
allows for replacing values in the let namespace -- this extension has not been
accepted into the Zope core, however, as it was held to facilitate "DTML
abusee".
So, <dtml-call "REQUEST.set( 'varname', newValue )"> is your best bet for having
values last through the end of your method (or <dtml-call "REQUEST.other.update(
sourceDictionary )"> for the truly dedicated).
--
=========================================================
Tres Seaver tseaver@palladion.com 713-523-6582
Palladion Software http://www.palladion.com