[ZPT] ZPT in ZSQL Method
Corey Saltiel
corey@axcelerant.com
Sun, 26 Jan 2003 13:33:05 -0800
--Boundary-00=_RQFN+e8+CQCz1pI
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello!
I'm new to Zope. I like ZPT alot; I don't like DTML at all.
I'd prefer to never use or learn DTML until later when I feel like it, and
instead concentrate purely on the basic Zope administration/use and Python and
ZPT.
Zope + ZPT + Python is enough to tackle as it is, without throwing DTML into the
mix...
SO - I sent a question to the zope@zope.org list, which resulted in this latest
response that I recently sent, and am now forwarding here.
My question essentialy boils down to this: wouldn't it be nice if we could use
ZPT/Tal in Z SQL Methods?
Is such a request/wish reasonable, or is it totally out of the question?
As an aside, I'd like to pull a resulting value out of a Z SQL Method without
using tal:repeat. Is this possible? The ZSQL Method in question only ever
returns a single value.
I'd like to do something like:
<p><span tal:replace="here/select_CompanyID('CompanyId')">CompanyId</span></p>
Rather than:
<span tal:repeat="item here/select_CompanyID">
<p><span tal:replace="item/CompanyId">CompanyId</span></p>
</span>
Thanks for the clue/help!
--Boundary-00=_RQFN+e8+CQCz1pI
Content-Type: message/rfc822;
name="forwarded message"
Content-Description: Corey Saltiel <corey@axcelerant.com>: Re: [Zope] sorry for lame question...
Content-Transfer-Encoding: 7bit
From: Corey Saltiel <corey@axcelerant.com>
Organization: Axcelerant
To: zope@zope.org
Subject: Re: [Zope] sorry for lame question...
Date: Sun, 26 Jan 2003 12:44:39 -0800
User-Agent: KMail/1.5
References: <200301261038.04290.corey@axcelerant.com> <3E34386C.3030205@members.netsolution-net.de>
In-Reply-To: <3E34386C.3030205@members.netsolution-net.de>
X-KMail-Link-Message: 5132
X-KMail-Link-Type: reply
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200301261244.39568.corey@axcelerant.com>
Status: RO
X-Status: S
X-KMail-EncryptionState:
X-KMail-SignatureState:
On Sunday 26 January 2003 11:35 am, Martin Gebert wrote:
> Corey Saltiel schrieb:
> ><span tal:replace="here/my_ZSql_method">
> >
> >Which provides:
> >
> >"<Shared.DC.ZRDB.Results.Results instance at 0x8c6df8c>"
> >
> >I don't want the instance - I want the value, of course.
>
> This is the object reference, and the values are, row by row, *in* this
> object. tal:replace doesn't iterate over the rows, but replaces the tag
> by the value of the object, which is this reference.
>
Understood. As a programmer, that "<Shared.DC.ZRDB.Results.Results instance at
0x8c6df8c>" result was obviously a reference - which I didn't want.
> >( My lack of Python knowhow may make the obvious less so )
>
> Seems so. OO programming knowledge would help, too.
>
It actualy appears, now that I see the correct TAL syntax - that neither
Python *or* OOP knowledge ( which I have plenty of - I'm just not a python
programmer yet ) - would have helped me guess the correct way of pulling
ZSql row values with ZPT. I only had to guess because the official
documentation did not explain or demonstrate how.
> >Why can't ZPT be used in other places, like ZSql methods?
>
> 'cause ZPT isn't designed for logic, but you need logic in Z SQL (if,
> group, and etc.).
>
There's no logic in the following ZSql:
select CompanyId
from Users
where UserId=<dtml-sqlvar expr="_.SecurityGetUser().getUserName()" type="string">
Why can not the following be done:
select CompanyId
from Users
where UserId=tal:content="user/getUserName"
( this was what I, as a newbie, tried with my first ZSql method )
Or something like:
select CompanyId
from Users
where UserId=tal:sqlvar="python: modules['AccessControl'].getSecurityManager().getUserName()"
Notice how ZPT and DTML both have different idiosyncrasies - it's lame to have
to learn both! If there wasn't so much "magic" involved ( *much* less so with
ZPT compared to DTML ), it wouldn't be such a problem.
> > There is some serious
> >confusion on where to use ZPT and where to use DTML.
>
> Use ZPT in Page Templates, DTML in DTML-Documents, -Methods and Z SQL
> Methods. That's that.
>
It makes sense that one would not stuff ZPT/TAL into a "DTML Document" or
a "DTML Method", just as it makes sense to not throw perl into a "Script
(Python)"... that wasn't what I was getting at.
I was talking about the overlap between ZPT and DTML.
It's obviously and understandably preferable - from a strictly academic
standpoint - to use ZPT wherever possible, than DTML - which destroys all
concepts of logic/presentation separation, and is rather ugly in my view.
When a ton of the official, easily accessable docs out there all mostly use
DTML ( even the Zope Tutorial! ) - then it really reduces the ease and thus
the likelyhood of a newbie to ever start right off with ZPT. They'll either
just go with DTML for everything, because it takes effort to learn and that's
what most of the docs present; or they'll just get frustrated.
> > Why should a new user be
> >required to learn *both* -- especialy when it's arguable that ZPT is more
> >"correct" ( in so far as much as better separation of logic from
> > presentation, html/xml friendly, etc., etc. )
>
> See above - ZPT is for design and layout, not for logic. "Better" means
> "closer to the ideal of separating content and layout" here. DTML mixes
> both and therefore is more a "write only language" (read: bad to
> administrate). In ZPT you additionally need Python for logic (which you
> needed with DTML for everything more complicated anyways...).
>
Then I - as someone who prefers to learn and strictly use ZPT - should be able
to to write that ZSql method with ZPT, rather than DTML. And if/when logic is
required, then I'd have to use some python in addition.
> >I get the distinct impression from the zope-dev list that ZPT is,
> > generaly, the new desired replacement for DTML for most uses.
>
> You should now understand why, and in which cases. Or not...?
>
I understand - and very much appreciate! - the fact that I could reasonably
use ZPT and ZPT w/ python as a complete replacement for DTML documents and
DTML methods. This is cool.
What sucks, is that I have to learn DTML - which I'd rather didn't exist! -
just in order to do anything useful with ZSql methods. This defeats my desire
to learn as little as possible in order to get as far as possible in as short
a time period as possible. It also throws a serious monkey-wrench into my
learning curve. This is not being lazy - it's being productive. Needing to
learn both DTML and ZPT reduces my productivity.
Am I making any sense here, or just rambling?
I guess, to simplify - all I'm looking for is the ability to use ZPT in Zsql
methods... is that such a crazy idea?
--Boundary-00=_RQFN+e8+CQCz1pI--