[Zope] Re: Defining a dictionary in ZPT?
ok, thanks Duncan ul li tal:define=query nocall:here/testquery tal:repeat=result python:query(id='IT') span tal:replace=result/lastnamelastname 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 ___ 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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
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/firsnamefirstname goes here/span /li /ul On 11/2/07, michael nt milne [EMAIL PROTECTED] 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 [EMAIL PROTECTED] wrote: Hi Josef ul li tal:define=query here/testquery tal:repeat=result python:query(id='IT') span tal:replace=repeat/resultfirstname goes here/span /li /ul gives the same AttributeError: Results instance has no __call__ method As does span tal:replace=repeat/result/firstnameFirst Name/span As does span tal:replace=result/firstnameFirst Name/span ! Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-) On 11/2/07, Josef Meile [EMAIL PROTECTED] 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'].firstnameFirst 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/firstnameFirst 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 ___ 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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
ok, thanks Duncan ul li tal:define=query nocall:here/testquery tal:repeat=result python:query(id='IT') span tal:replace=result/lastnamelastname 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 [EMAIL PROTECTED] wrote: michael nt milne [EMAIL PROTECTED] wrote: li tal:define = query here/testquery tal:repeat=result python:query(id='IT') span tal:replace=python:repeat['result'].firstnameFirst Name/spannbsp; /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 ___ 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 )
[Zope] Re: Defining a dictionary in ZPT?
michael nt milne [EMAIL PROTECTED] wrote: li tal:define = query here/testquery tal:repeat=result python:query(id='IT') span tal:replace=python:repeat['result'].firstnameFirst Name/spannbsp; /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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
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 [EMAIL PROTECTED] wrote: Hi Josef ul li tal:define=query here/testquery tal:repeat=result python:query(id='IT') span tal:replace=repeat/resultfirstname goes here/span /li /ul gives the same AttributeError: Results instance has no __call__ method As does span tal:replace=repeat/result/firstnameFirst Name/span As does span tal:replace=result/firstnameFirst Name/span ! Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-) On 11/2/07, Josef Meile [EMAIL PROTECTED] 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'].firstnameFirst 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/firstnameFirst 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 ___ 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 )
[Zope] Re: Defining a dictionary in ZPT?
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'].firstnameFirst Name/spannbsp; /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/firstnameFirst 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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
Hi Josef ul li tal:define=query here/testquery tal:repeat=result python:query(id='IT') span tal:replace=repeat/resultfirstname goes here/span /li /ul gives the same AttributeError: Results instance has no __call__ method As does span tal:replace=repeat/result/firstnameFirst Name/span As does span tal:replace=result/firstnameFirst Name/span ! Thanks for your help. Not easy this ZPT!, even when you have read the documentation :-) On 11/2/07, Josef Meile [EMAIL PROTECTED] 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'].firstnameFirst 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/firstnameFirst 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 ___ 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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
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 ___ 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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
So use DTML? Or NKOTB? :-) On 11/2/07, Stefan H. Holek [EMAIL PROTECTED] 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 ___ 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 )
[Zope] Re: Defining a dictionary in ZPT?
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'].firstnameFirst Name/spannbsp; /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 )
Re: [Zope] Re: Defining a dictionary in ZPT?
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 [EMAIL PROTECTED] 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'].firstnameFirst Name/spannbsp; /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 ___ 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 )