Hi I've got this piece of code which is returning a keyerror on 'results' as I haven't set up a dictionary for the variables. I'm not sure what the syntax is for this within the ZPT. I've read about the 'options' dictionary. Can I use that? Thanks <ul> <span tal:define="query here/testquery"> <li tal content="results python: query(id='IT')"> <span tal:replace="results/firstname">First Name</span> </li> </span> </ul> -- michael
On Thu, Nov 01, 2007 at 12:48:04PM +0000, michael nt milne wrote:
Hi
I've got this piece of code which is returning a keyerror on 'results' as I haven't set up a dictionary for the variables. (snip) <span tal:define="query here/testquery"> <li tal content="results python: query(id='IT')"> <span tal:replace="results/firstname">First Name</span> </li>
"<li tal content" doesn't make any sense. I suspect you want that to be: <li tal:define="results ... -- Paul Winkler
yeah I have modified to this <li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li> but get this as a result. Thanks for the reply. Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method On 11/1/07, Paul Winkler <pw_lists@slinkp.com> wrote:
On Thu, Nov 01, 2007 at 12:48:04PM +0000, michael nt milne wrote:
Hi
I've got this piece of code which is returning a keyerror on 'results' as I haven't set up a dictionary for the variables. (snip) <span tal:define="query here/testquery"> <li tal content="results python: query(id='IT')"> <span tal:replace="results/firstname">First Name</span> </li>
"<li tal content" doesn't make any sense.
I suspect you want that to be:
<li tal:define="results ...
--
Paul Winkler _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
michael nt milne napsal(a):
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
1) don't make spaces around = in HTML attributes: tal:define="query here/testquery" 2) Why do you use repeat['result'] ? Can you point us to documentation where did you read it ? tal:replace="result/firstname" should work as expected or tal:replace="python:result['firstname']" in case of result is dictionary and you need to use python: for some reason. 3) what testquery returns ? I suppose it returns method, because you are calling this method wit parameter 'id', but I don't think you meant it in this way. -- Radim Novotny
1) don't make spaces around = in HTML attributes: tal:define="query here/testquery" a mistake 2) Why do you use repeat['result'] ? Can you point us to documentation where did you read it ? tal:replace="result/firstname" should work as expected or tal:replace="python:result[ 'firstname']" in case of result is dictionary and you need to use python: for some reason. http://wiki.zope.org/ZPT/RepeatVariable requires repeat to be called. I used this as previously using tal:replace="result/firstname produced a keyerror as I had no dictionaries set up. The repeat variable sets-up a dictionary automatically... 3) what testquery returns ? I suppose it returns method, because you are calling this method wit parameter 'id', but I don't think you meant it in this way. testquery returns a ZSQL query which works and is tested. The id variable is totally meant as we are passing through a dynamic variable from a ZPT page through to the ZSQL query. At the moment to simplify things! (required..) this variable is fixed to 'IT'. Thanks for your help On 11/1/07, Radim Novotny <novotny.radim@gmail.com> wrote:
michael nt milne napsal(a):
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
1) don't make spaces around = in HTML attributes: tal:define="query here/testquery"
2) Why do you use repeat['result'] ? Can you point us to documentation where did you read it ? tal:replace="result/firstname" should work as expected or tal:replace="python:result['firstname']" in case of result is dictionary and you need to use python: for some reason.
3) what testquery returns ? I suppose it returns method, because you are calling this method wit parameter 'id', but I don't think you meant it in this way.
-- Radim Novotny
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
Hi Michael michael nt milne schrieb:
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method I suspect that result isn't a dictionary. Why don't you try to print result instead and see its type? Try this:
<span tal:replace="repeat/result"></span> You could also try the other sintax for your zpt: <span tal:replace="repeat/result/firstname">First Name</span> Regards Josef
Hi Josef <ul> <li tal:define="query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="repeat/result">firstname goes here</span> </li> </ul> gives the same
AttributeError: Results instance has no __call__ method
As does <span tal:replace="repeat/result/firstname">First Name</span> As does <span tal:replace="result/firstname">First Name</span> ! Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-) On 11/2/07, Josef Meile <jmeile@hotmail.com> wrote:
Hi Michael
michael nt milne schrieb:
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method I suspect that result isn't a dictionary. Why don't you try to print result instead and see its type? Try this:
<span tal:replace="repeat/result"></span>
You could also try the other sintax for your zpt: <span tal:replace="repeat/result/firstname">First Name</span>
Regards Josef _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
ps for completeness here is the testquery ZSQL which works fine when tested in the ZMI and manually inputting the id variable. select * from tblEmployees where department = (<dtml-sqlvar id type="string">) order by 'location' I have 'id' in the argument field Thanks On 11/2/07, michael nt milne <michael.milne@gmail.com> wrote:
Hi Josef
<ul> <li tal:define="query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="repeat/result">firstname goes here</span> </li> </ul>
gives the same
AttributeError: Results instance has no __call__ method
As does
<span tal:replace="repeat/result/firstname">First Name</span>
As does
<span tal:replace="result/firstname">First Name</span>
!
Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-)
On 11/2/07, Josef Meile <jmeile@hotmail.com> wrote:
Hi Michael
michael nt milne schrieb:
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method I suspect that result isn't a dictionary. Why don't you try to print result instead and see its type? Try this:
<span tal:replace="repeat/result"></span>
You could also try the other sintax for your zpt: <span tal:replace="repeat/result/firstname">First Name</span>
Regards Josef _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
-- michael
So doing some more routing around on the lists I saw this advice
FWIW you might want to call the query or execute methods directly on the DA connection object if they are supported.
Therefore my db connection object is ado_db_connection. Modifying my code to the below and calling the query method of the adapter now gives me an 'insufficient priviledges' in my Plone site...Nearly there I feel. Strange as I am logged in as the uberuser... <ul> <li tal:define="query here/testquery" tal:repeat="result python: context.ado_db_connection().query(id='IT')"> <span tal:replace="repeat/result/firsname">firstname goes here</span> </li> </ul> On 11/2/07, michael nt milne <michael.milne@gmail.com> wrote:
ps for completeness
here is the testquery ZSQL which works fine when tested in the ZMI and manually inputting the id variable.
select * from tblEmployees where department = (<dtml-sqlvar id type="string">) order by 'location'
I have 'id' in the argument field
Thanks
On 11/2/07, michael nt milne <michael.milne@gmail.com > wrote:
Hi Josef
<ul> <li tal:define="query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="repeat/result">firstname goes here</span> </li> </ul>
gives the same
AttributeError: Results instance has no __call__ method
As does
<span tal:replace="repeat/result/firstname">First Name</span>
As does
<span tal:replace="result/firstname">First Name</span>
!
Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-)
On 11/2/07, Josef Meile <jmeile@hotmail.com > wrote:
Hi Michael
michael nt milne schrieb:
yeah I have modified to this
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method I suspect that result isn't a dictionary. Why don't you try to print result instead and see its type? Try this:
<span tal:replace="repeat/result"></span>
You could also try the other sintax for your zpt: <span tal:replace="repeat/result/firstname">First Name</span>
Regards Josef _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
-- michael
-- michael
"michael nt milne" <michael.milne@gmail.com> wrote:
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method
That is because you already called the function. The tal:define="query here/testquery" is (roughly) equivalent to: tal:define="query python:here.testquery()". If you want to use a path expression which evaluates to something callable so that you have a shorter name later when you call it then you explicitly say you don't want to call it: tal:define="query nocall:here/testquery"
ok, thanks Duncan <ul> <li tal:define="query nocall:here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="result/lastname">lastname goes here</span> </li> </ul> works! I went down a blind alley with calling the database adapter due to confusion over the error message produced. Backs up my point about more friendly and usable error messages. Much appreciated! On 11/2/07, Duncan Booth <duncan.booth@suttoncourtenay.org.uk> wrote:
"michael nt milne" <michael.milne@gmail.com> wrote:
<li tal:define = "query here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="python:repeat['result'].firstname">First Name</span> </li>
but get this as a result. Thanks for the reply.
Module Products.PTProfiler.ProfilerPatch, line 32, in __patched_call__ Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__ - __traceback_info__: query(id='IT') Module Python expression "query(id='IT')", line 1, in <expression> AttributeError: Results instance has no __call__ method
That is because you already called the function.
The tal:define="query here/testquery" is (roughly) equivalent to: tal:define="query python:here.testquery()". If you want to use a path expression which evaluates to something callable so that you have a shorter name later when you call it then you explicitly say you don't want to call it:
tal:define="query nocall:here/testquery"
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- michael
The only point being backed up by this thread, IMO, is that "Thou shalt not code in TALES." Stefan On 2. Nov 2007, at 12:53, michael nt milne wrote:
Backs up my point about more friendly and usable error messages.
-- Anything that, in happening, causes something else to happen, causes something else to happen. --Douglas Adams
So use DTML? Or NKOTB? :-) On 11/2/07, Stefan H. Holek <stefan@epy.co.at> wrote:
The only point being backed up by this thread, IMO, is that "Thou shalt not code in TALES."
Stefan
On 2. Nov 2007, at 12:53, michael nt milne wrote:
Backs up my point about more friendly and usable error messages.
-- Anything that, in happening, causes something else to happen, causes something else to happen. --Douglas Adams
-- michael
ok, thanks Duncan
<ul> <li tal:define="query nocall:here/testquery" tal:repeat="result python:query(id='IT')"> <span tal:replace="result/lastname">lastname goes here</span>
</li> </ul> Good that you got it working. By the way, why do you need to define "query"? Do you really need a reference to the testquery function? Won't be enough by writing:
<li tal:repeat="result python:here.testquery(id='IT')"> Or are you using "query" somewhere else? Best regards Josef
participants (7)
-
Duncan Booth -
Josef Meile -
michael nt milne -
michael.milne@gmail.com -
Paul Winkler -
Radim Novotny -
Stefan H. Holek