[Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Frank Burkhardt
Hi,

in Zope2 there's a test() method that can be used in TAL (*). Is there something
comparable in Zope3?

I know how to write such a method but how to make it available in the
namespace of TALES-python:-expressions? I would like to write expressions
like this:

div tal:attributes=class python: 'foo' + test(condition == True,' bar','') /

Is this possible?

Regards,

Frank

(*) found it here:
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AdvZPT.stx
(look for 'test(' )
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Andreas Jung



--On 1. Februar 2006 09:04:36 +0100 Frank Burkhardt [EMAIL PROTECTED] wrote:


Hi,

in Zope2 there's a test() method that can be used in TAL (*). Is there
something comparable in Zope3?

I know how to write such a method but how to make it available in the
namespace of TALES-python:-expressions? I would like to write
expressions like this:

div tal:attributes=class python: 'foo' + test(condition == True,'
bar','') /



You can write this in Python as

   condition and true_expression or false_expression

-aj


pgpV4jynQWzQQ.pgp
Description: PGP signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Frank Burkhardt
On Wed, Feb 01, 2006 at 09:04:36AM +0100, Frank Burkhardt wrote:

[snip]

 div tal:attributes=class python: 'foo' + test(condition == True,' bar','') 
 /
 
 Is this possible?

Impressing simple solution :-) .

Thank you Andreas and Igor.

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Gary Poster


On Feb 1, 2006, at 3:17 AM, Frank Burkhardt wrote:


On Wed, Feb 01, 2006 at 09:04:36AM +0100, Frank Burkhardt wrote:

[snip]

div tal:attributes=class python: 'foo' + test(condition ==  
True,' bar','') /


Is this possible?


Impressing simple solution :-) .


FWIW the classic Zope 3 solution is to say Don't do that in the  
template!  Do it in the view class!.  I'll let others add vigor, if  
they wish. I just wanted you to know the purist answer in case you  
cared. ;-)


Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Andreas Jung



--On 1. Februar 2006 07:56:47 -0500 Gary Poster [EMAIL PROTECTED] wrote:



On Feb 1, 2006, at 3:17 AM, Frank Burkhardt wrote:


On Wed, Feb 01, 2006 at 09:04:36AM +0100, Frank Burkhardt wrote:

[snip]


div tal:attributes=class python: 'foo' + test(condition ==
True,' bar','') /

Is this possible?


Impressing simple solution :-) .


FWIW the classic Zope 3 solution is to say Don't do that in the
template!  Do it in the view class!.  I'll let others add vigor, if
they wish. I just wanted you to know the purist answer in case you
cared. ;-)



If you have only one python: statement within your template then a view 
class is pretty much overhead (and a waste of manpower to write it)...


just my 2 cents,
-aj




pgpozO5biEJFD.pgp
Description: PGP signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Gary Poster


On Feb 1, 2006, at 8:07 AM, Andreas Jung wrote:




--On 1. Februar 2006 07:56:47 -0500 Gary Poster [EMAIL PROTECTED] wrote:


FWIW the classic Zope 3 solution is to say Don't do that in the
template!  Do it in the view class!.  I'll let others add vigor, if
they wish. I just wanted you to know the purist answer in case you
cared. ;-)


If you have only one python: statement within your template then a  
view class is pretty much overhead (and a waste of manpower to  
write it)...


I hear ya.  I figured someone ought to wave the purist flag, at least  
half-heartedly, though. :-)


Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


RE: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Roger Ineichen
Hi Andreas

[...]
 
  FWIW the classic Zope 3 solution is to say Don't do that in the
  template!  Do it in the view class!.  I'll let others add vigor, if
  they wish. I just wanted you to know the purist answer in case you
  cared. ;-)
 
 
 If you have only one python: statement within your template 
 then a view 
 class is pretty much overhead (and a waste of manpower to write it)...
 
 just my 2 cents,
 -aj
 
Don't forget about the better overview in the project if you put
application logic in view classes.
(No more page template reading and macro searching for a code review)

And there are also security related aspects. Doing to much
in ZPT will force scripters to map methods to the traversal namespace
and ends in accessing context attributes in ZPT like context/@@title

Regards
Roger Ineichen

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Benji York

Andreas Jung wrote:

Frank Burkhardt [EMAIL PROTECTED] wrote:


in Zope2 there's a test() method that can be used in TAL (*). Is there
something comparable in Zope3?


You can write this in Python as

   condition and true_expression or false_expression


In Python 2.5 you'll be able to write

true_expression if condition else false_expression

--
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


RE: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Andreas Jung



--On 1. Februar 2006 14:25:42 +0100 Roger Ineichen [EMAIL PROTECTED] wrote:


Don't forget about the better overview in the project if you put
application logic in view classes.
(No more page template reading and macro searching for a code review)



I knew that you love those kind of discussions :-) I agree mostly but there 
are situations where less code and less configuration is more :-)
Something like test() or python: condtion and expr1 or expr2 are more or 
less self-explaining...no need to hide such code just for the sake of 
hiding it.


-aj



pgpW1pEzhY31R.pgp
Description: PGP signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Michael Dudzik
On Wed, 01 Feb 2006 09:07:17 +0100, Andreas Jung
[EMAIL PROTECTED] said:
 
 
 --On 1. Februar 2006 09:04:36 +0100 Frank Burkhardt [EMAIL PROTECTED] wrote:
 
  Hi,
 
  in Zope2 there's a test() method that can be used in TAL (*). Is there
  something comparable in Zope3?
 
  I know how to write such a method but how to make it available in the
  namespace of TALES-python:-expressions? I would like to write
  expressions like this:
 
  div tal:attributes=class python: 'foo' + test(condition == True,'
  bar','') /
 
 
 You can write this in Python as
 
 condition and true_expression or false_expression

That doesn't work under some conditions:

C and A or B where C is a boolean

if C is false it evaluates to B
if C is true it evaluates to A EXCEPT when bool(A) == false

example:

C and None or 7 ALWAYS evaluates to 7

However, the expression (B,A)[C] always works if C is a boolean

I'm using that until Python 2.5 comes along.

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Igor Stroh
Michael Dudzik wrote:
 On Wed, 01 Feb 2006 09:07:17 +0100, Andreas Jung
[..]
in Zope2 there's a test() method that can be used in TAL (*). Is there
something comparable in Zope3?

I know how to write such a method but how to make it available in the
namespace of TALES-python:-expressions? I would like to write
expressions like this:

div tal:attributes=class python: 'foo' + test(condition == True,'
bar','') /

You can write this in Python as

condition and true_expression or false_expression
 
 
 That doesn't work under some conditions:
 
 C and A or B where C is a boolean
 
 if C is false it evaluates to B
 if C is true it evaluates to A EXCEPT when bool(A) == false
 
 example:
 
 C and None or 7 ALWAYS evaluates to 7

Just make it 'not C and 7 or None' :)

Igor
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Fwd: Re: [Zope3-Users] test() in TALES in Zope3

2006-02-01 Thread Michael Dudzik
On Wed, 01 Feb 2006 19:15:13 +0100, Igor Stroh [EMAIL PROTECTED] said:
 Michael Dudzik wrote:
  On Wed, 01 Feb 2006 09:07:17 +0100, Andreas Jung
 [..]
 in Zope2 there's a test() method that can be used in TAL (*). Is there
 something comparable in Zope3?
 
 I know how to write such a method but how to make it available in the
 namespace of TALES-python:-expressions? I would like to write
 expressions like this:
 
 div tal:attributes=class python: 'foo' + test(condition == True,'
 bar','') /
 
 You can write this in Python as
 
 condition and true_expression or false_expression
  
  
  That doesn't work under some conditions:
  
  C and A or B where C is a boolean
  
  if C is false it evaluates to B
  if C is true it evaluates to A EXCEPT when bool(A) == false
  
  example:
  
  C and None or 7 ALWAYS evaluates to 7
 
 Just make it 'not C and 7 or None' :)

Sure, but what about when you don't know the boolean value ahead of
time, like:

   C and f(x) or g(x)

   On the other hand, (g(x), f(x))[C] works every time

To be fair, both g(x) and f(x) are evaluated while

   f(x) if C else g(x)  # python 2.5, only evaluates the appropriate
   function.

Still, I mostly spoke up because if one starts to use an idiom like:

python:C and 'somestring' or 'anotherstring'

you have to realize that

python:C and '' or 'anotherstring'

will fail.  An idiom that breaks so easily doesn't seem so useful.

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users