[Paul Winkler]
I guess I don't understand the goal. Are we trying to make it
so that zpt authors don't have to know any python?

[Chris Withers]
For me, that would be ideal...

[Paul Winkler]
I really think that's a mistake.

Guys, that line of thinking is a distraction. ZPT authors ought to learn Python. The issue is deeper than that. I'll explain below.

[Paul Winkler]
Assuming that TALES python expressions are banned/discouraged/whatever, [...]

Python expressions won't be banned. I will never consider them discouraged for all cases, either. There will always be a need for constructs like:

<div tal:condition="python: a == b">...</div>
<div tal:condition="python: (a and b) or c">...</div>

However, the following is quite bad:

<tal:x define="ss nocall:modules/Products/PythonScripts/standard">
 <a tal:attributes="href python: ss.url_quote(some_url)" />

This is un-Pythonic in numerous ways.

- You can't use the import statement. In fact, you can't use any statements at all--only expressions.

- The nocall: prefix.

- The name 'modules' is present automatically along with many other names that aren't in the Python builtins namespace.

- Importing using a path expression.

- Binding a variable to a value without an equal sign.

- You have to prefix Python expressions with "python:".

- You have to be careful not to use double quotes in expressions. (Ampersands and less-than/greater-than signs are tricky too. Watch out for pairs of hyphens!)

Zope 2's method of slightly simplifying this is to write a two-line script and find it through implicit acquisition. The overhead of invoking a script is somewhat large, but here's what the template would look like anyway.

<a tal:attributes="href python: here.url_quote(some_url)" />

Zope 3 will not have implicit acquisition. In fact, no system but Zope 2 has implicit acquisition. That leaves us with no possible way to write the above statement in non-implicit Python! No matter what you do, you need some help from another kind of expression. Until recently, here was the way to write it in Zope 3.

<tal:x define="url_quote nocall:here/++acquire++url_quote">
  <a tal:attributes="href python: url_quote(some_url)" />

That alternative is just as complicated and un-Pythonic as importing a module in a template. I can't think of a better way to write this given the limitations of Zope 2 ZPT, without the giant implicit acquisition band-aid. Can you?

Zope 3's new alternative looks about like this:

<a tal:attributes="href here/format:url_quote" />

To me, that's a vast improvment, and it's only one example.

You know what was actually wrong with DTML? The lack of Python Scripts. Without Python Scripts, everyone used DTML as a programming language. Once Python Scripts came around, DTML became a reasonable templating language again. If DTML used TALES expressions, it would be just as clean as ZPT.


Zope-Dev maillist - [EMAIL PROTECTED]
** No cross posts or HTML encoding! **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )

Reply via email to