I'm completely new to Zope and am starting out with something I imagine is amazingly simple - but after many attempts and perusals of docs and lists, I'm still unable to figure this one out... Using ZPT - how do I get the value returned from a ZSql method? This method only ever returns *one* value; I'd rather not do a tal:repeat if I'm able to. The best I can do is: <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. ( My lack of Python knowhow may make the obvious less so ) Also - could someone point me to the document(s) that explain or show an example of this? I was unable to find it explained anywhere. There's a ton of stuff on DTML - but I'm only interested in using ZPT wherever possible. Shouldn't the Zope Book ( I'm reading v. 2.6 ) try to use ZPT in all it's standard examples rather than DTML? Why can't ZPT be used in other places, like ZSql methods? There is some serious confusion on where to use ZPT and where to use DTML. 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. ) I get the distinct impression from the zope-dev list that ZPT is, generaly, the new desired replacement for DTML for most uses. Thanks!
--On Sonntag, 26. Januar 2003 10:38 -0800 Corey Saltiel <corey@axcelerant.com> wrote:
I'm completely new to Zope and am starting out with something I imagine is amazingly simple - but after many attempts and perusals of docs and lists, I'm still unable to figure this one out...
Using ZPT - how do I get the value returned from a ZSql method? This method only ever returns *one* value; I'd rather not do a tal:repeat if I'm able to.
The best I can do is:
<span tal:replace="here/my_ZSql_method">
try something like <span tal:repeat="brain here/my_zsq_method"> ... the brain variable does represent a single row of the result of your SQL query. You should be able to access the cols by "brain/<column_name>" where <column_name> is the name of column returned by the query. -aj
On Sunday 26 January 2003 10:52 am, Andreas Jung wrote:
--On Sonntag, 26. Januar 2003 10:38 -0800 Corey Saltiel
<corey@axcelerant.com> wrote: <snip>
Using ZPT - how do I get the value returned from a ZSql method? This method only ever returns *one* value; I'd rather not do a tal:repeat if I'm able to.
<snip>
try something like
<span tal:repeat="brain here/my_zsq_method">
Thanks for the help!
... the brain variable does represent a single row of the result of your SQL query. You should be able to access the cols by "brain/<column_name>" where <column_name> is the name of column returned by the query.
'brain'? Certainly not particularly intuitive... How would I have gone about finding this info easily on my own, as a newbie? The ZPT reference in the Zope book doesn't mention this anywhere... Zope is really killer - it's just a serious pain to start because of the "magic" involved, and the docs and info can be difficult to locate - regardless of how good a web-searcher one may be.
--On Sonntag, 26. Januar 2003 11:18 -0800 Corey Saltiel <corey@axcelerant.com> wrote:
On Sunday 26 January 2003 10:52 am, Andreas Jung wrote:
--On Sonntag, 26. Januar 2003 10:38 -0800 Corey Saltiel
<corey@axcelerant.com> wrote: <snip>
Using ZPT - how do I get the value returned from a ZSql method? This method only ever returns *one* value; I'd rather not do a tal:repeat if I'm able to.
<snip>
try something like
<span tal:repeat="brain here/my_zsq_method">
Thanks for the help!
... the brain variable does represent a single row of the result of your SQL query. You should be able to access the cols by "brain/<column_name>" where <column_name> is the name of column returned by the query.
'brain'? Certainly not particularly intuitive...
How would I have gone about finding this info easily on my own, as a newbie?
The ZPT reference in the Zope book doesn't mention this anywhere...
This is not a ZPT issue but a ZSQL issue. Since tal:repeat just iterates of a sequence (ZPT neither care about what this sequence contains nor where is does come from) it is not described in the ZPT reference but it should be part of the ZSQL method documentation. -aj
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. Andreas has already answered how to use tal:repeat, so I don't go more into it...
( My lack of Python knowhow may make the obvious less so )
Seems so. OO programming knowledge would help, too.
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 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.
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...).
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...? Martin
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?
On Sun, Jan 26, 2003 at 10:38:04AM -0800, Corey Saltiel wrote:
The best I can do is:
<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.
Untested, but what about <span tal:replace="here/my_Zsql_method()">, perhaps with any needed parameters inside the parentheses? At least for most of my experience, if calling some sort of logic code results in some sort of instance or reference, then adding the parentheses at the end to make it a proper function call tends to fix it. DTML would let you be sloppy with the calling convention, where ZPT and Python itself tend to be more strict. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
On Sunday 26 January 2003 01:06 pm, Mike Renfro wrote:
On Sun, Jan 26, 2003 at 10:38:04AM -0800, Corey Saltiel wrote:
The best I can do is:
<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.
Untested, but what about <span tal:replace="here/my_Zsql_method()">, perhaps with any needed parameters inside the parentheses? <snip>
Thanks, and close! I just got this from the ZPT list: <p tal:content="python:here.select_CompanyID()[0].CompanyId">CompanyId</p> Works like a charm - no tal:replace necessary! Cool. Cheers, Corey
Hi Corey, --On Sonntag, 26. Januar 2003 10:38 -0800 Corey Saltiel <corey@axcelerant.com> wrote:
I'm completely new to Zope and am starting out with something I imagine is amazingly simple - but after many attempts and perusals of docs and lists, I'm still unable to figure this one out...
Using ZPT - how do I get the value returned from a ZSql method? This method only ever returns *one* value; I'd rather not do a tal:repeat if I'm able to.
Whats wrong with repeat here? repeat would give you if <yourmethod> and variabe defining the same time. You can do it without repeat, but it will be worser. <span tal:repeat="foo here/your_ZSql_method" tal:content="foo/column">wopp</span>
The best I can do is:
<span tal:replace="here/my_ZSql_method">
Which provides:
"<Shared.DC.ZRDB.Results.Results instance at 0x8c6df8c>"
ZSQL method always return an object which behaves like a list of zero or more objects which behave like an dictionary and an object with attributes the same time (so you can write result[index].column or result[index]['column']
I don't want the instance - I want the value, of course.
( My lack of Python knowhow may make the obvious less so )
You should really really not hesiate to learn python any more :) Just give the tutorial on python.org a try, it will clarify much of your questions out. Keep in mind: python does not bite. :)
Also - could someone point me to the document(s) that explain or show an example of this? I was unable to find it explained anywhere.
There's a ton of stuff on DTML - but I'm only interested in using ZPT wherever possible. Shouldn't the Zope Book ( I'm reading v. 2.6 ) try to use ZPT in all it's standard examples rather than DTML?
I would like to see that too. But unfortunately...
Why can't ZPT be used in other places, like ZSql methods? There is some
Guess why ;) Try to build up an example ;)
serious confusion on where to use ZPT and where to use DTML. 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. )
I get the distinct impression from the zope-dev list that ZPT is, generaly, the new desired replacement for DTML for most uses.
Um. The replacement consists of Python Scripts + ZPT, not ZPT allone.
participants (5)
-
Andreas Jung -
Corey Saltiel -
Martin Gebert -
Mike Renfro -
Tino Wildenhain