[ZPT] Possible changes to path-related

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Mon, 30 Apr 2001 11:52:16 +1000


Evan Simpson wrote:
> I'm almost ready to release ZPT 1.2, and I'm trying to nail down the
> implementation of:
> http://dev.zope.org/Wikis/DevSite/Projects/ZPT/ActOnlyIfPathExists
>
> In the process, I decided that overloading 'exists' was not the best
> solution.  Instead, I suggest adding an 'if' modifier that could operate
> alone or in combination with 'exists'.  It would cancel the TAL action using
> a path expression if the value is false.  When combined with 'exists', it
> would do so if the path is undefined, but return the rendered value if the
> path is defined.
>
> Combining path expression types like this would be messy, and I realized
> that it doesn't need to be implemented that way.  We can replace these
> multiple expression types with simple path expression prefixes, as described
> at:
> http://dev.zope.org/Wikis/DevSite/Projects/ZPT/PathExpressionVariants
> 
> With these two proposals, we could modify an expression such as
> 'request/foo' four ways (plus any of these with nocall added):
> 
> 1. request/foo
>     Return the value of 'request/foo' if it is defined, otherwise raise an
> exception.
> 2. if request/foo
>     Return the value of 'request/foo' if it is true, raise an exception if
> it is undefined, otherwise cancel the action.
> 3. if exists request/foo
>     Return the value of 'request/foo' if it is defined, otherwise cancel the
> action.
> 4. exists request/foo
>     Return true (1) if the value of 'request/foo' is defined, otherwise
> return false (0).
> 
> Please comment immediately, if you can.  I'd like to release 1.2 tomorrow,
> hopefully with these features.

Ow, that was quick turnaround on major changes to the proposal.
Unfortunately we Down Under had a public holiday on Wednesday last week - I
ate some bad salami and got sick and was off for the rest of the week too.
So I missed the debate :(

My primary concern with the above proposal (well, implementation now ;) is
that it's entering the realm of Spooky Black Magic coding. This was raised
by Godefroid Chapelle in his mail last week. Combine the ingredients in
just the right way, and wondrous things will happen. 'if' means one thing
by itself. 'exists' means one thing by itself. 'if exists' means something
again (even if similar). What does 'exists if' mean? Do you have a use case
for the above definition of the behaviour of "if request/foo"? I'm
struggling to think of a situation in which it'd be used. Change the
definition of 'if' to 'if exists' and I think we're in a more sane place.
'if' and 'exists' may be combined, but the 'if' won't actually do anything.
'if' and 'nocall' may be combined safely (and, possibly, usefully). Anyway,
that's the "my 2c" part of this email :)


So, I plugged in Zope 2.3.2 and the 1.2 PageTemplate releases this morning.
I replaced my lazy: bits with (if exists) bits. It seems, at first glance,
that this new mechanism doesn't actually work.

  <input type="text" name="foo:string" value="Sample" tal:attributes="value
(if exists) request/form/foo">

with no request/form/foo will result in

  <input type="text" name="foo:string"
value="Products.PageTemplates.TALES.Undefined">

when I would have expected 

  <input type="text" name="foo:string" value="Sample">

...?

Also, lazy: didn't care about the actual value returned - this is important
for the example above if the request has an empty string value in it (the
user has deleted the text "Sample" and submitted). The stuff up one entry,
so we feed the form back to them. They now see a form with the "Sample"
text back in their face. Not nice for them.

I also found that I could not:

   <input type="checkbox" tal:condition="(if) request/form/foo" CHECKED>
   <input type="checkbox" tal:condition="(if) not:request/form/foo">

... I got 'CompilerError: Invalid variable name "not:request"'. Is there
maybe a better way to do this?


   Richard

p.s. The zpt mailing list archive is still broken... Any hope of a fix
there?

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)