Re: [Zope] Re: Output only the first or a particular record using TAL
Julian Yap wrote: Another query I had was on the practice of using control flow (ie. if, for, etc.. statements). I guess the best way is to keep your control flow in Python scripts? Is this the common practise? Well, it seems to be that a little bit of python in a tal:condition is quite common, but if it gets more than that then yeah, probably move the logic out to a Script (Python)... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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: Output only the first or a particular record using TAL
--- Tino Wildenhain <[EMAIL PROTECTED]> wrote: > Am Mittwoch, den 28.09.2005, 16:32 +1000 schrieb Julian Yap: > > --- Chris Withers <[EMAIL PROTECTED]> wrote: > ... > > > Now, if you really can't stop your sql returning more than > one > > > row > > > (LIMIT 1 anyone?) then how about: > > > > > > > > tal:condition="customer"> > > > > > >Customer: > > > > > > > > > > > > > To have my SQL returning only just 1 row would require > another Z > > SQL Method, in which case it may as well be something like > > getCustomer. > > > > I'm still getting my head around TAL and how it works so I'm > not > > sure how the "python:customers and customers[0]" code works. > > > > Ideally, I want to use just the one Z SQL method (done) but > I > > guess it would be better coding to just reference the Z SQL > > method once. Currently the page template makes two calls to > the > > Z SQL method. Once for the customer header and another to > > retrieve the customer license details. Can you suggest how > this > > would be done? > > You could just wrap it in a simple python script: > > results=context.yourZSQLMethod() > > h=results[:1] # see python slice > b=results[1:] > > return context.yourPageTemplate(header=h,body=b) > > And in your ZPT use tal:repeat="chead options/header" > and options/body > > But maybe you can rething and rephrase your problem :-) Thanks Tino. Your example of using the Python script really opens my eyes to how everything fits together (I know Python). I'm not sure about the TAL statement you used (so what else is new). ... OK, I just got back from reading about the "options" keyword in Page Templates... Very useful. Thanks for the usage Python tip. I think that will get me going for a while. Another query I had was on the practice of using control flow (ie. if, for, etc.. statements). I guess the best way is to keep your control flow in Python scripts? Is this the common practise? ___ 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: Output only the first or a particular record using TAL
--- Chris Withers <[EMAIL PROTECTED]> wrote: > > I used the following and it works great (without some > formatting for > > clarity): > > > tal:condition="customer"> > > Customer: > tal:content="python:customer[0]['full_name']"> > > > > hmm, this strikes me as just plain wrong :-S > > Why is getCustomerLicenses returning more than one row if you > only want > the first one? In my original post I mentioned that getCustomerLicenses returns more than one row and I want to create something of a header. > If it only returned one row, then you could do: > > > >Customer: > > > > > ...no need for the condition or the yucky integer indexes. True. > Now, if you really can't stop your sql returning more than one > row > (LIMIT 1 anyone?) then how about: > > tal:condition="customer"> > >Customer: > > > To have my SQL returning only just 1 row would require another Z SQL Method, in which case it may as well be something like getCustomer. I'm still getting my head around TAL and how it works so I'm not sure how the "python:customers and customers[0]" code works. Ideally, I want to use just the one Z SQL method (done) but I guess it would be better coding to just reference the Z SQL method once. Currently the page template makes two calls to the Z SQL method. Once for the customer header and another to retrieve the customer license details. Can you suggest how this would be done? I'm also thinking further along the lines too of a page template, printing all customers with headers and details for each. This would use a SQL "GROUP BY" statement. .. But this is still out of my scope of knowledge. Regards, Julian ___ 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: Output only the first or a particular record using TAL
Am Mittwoch, den 28.09.2005, 16:32 +1000 schrieb Julian Yap: > --- Chris Withers <[EMAIL PROTECTED]> wrote: ... > > Now, if you really can't stop your sql returning more than one > > row > > (LIMIT 1 anyone?) then how about: > > > > > tal:condition="customer"> > > > >Customer: > > > > > > > > To have my SQL returning only just 1 row would require another Z > SQL Method, in which case it may as well be something like > getCustomer. > > I'm still getting my head around TAL and how it works so I'm not > sure how the "python:customers and customers[0]" code works. > > Ideally, I want to use just the one Z SQL method (done) but I > guess it would be better coding to just reference the Z SQL > method once. Currently the page template makes two calls to the > Z SQL method. Once for the customer header and another to > retrieve the customer license details. Can you suggest how this > would be done? You could just wrap it in a simple python script: results=context.yourZSQLMethod() h=results[:1] # see python slice b=results[1:] return context.yourPageTemplate(header=h,body=b) And in your ZPT use tal:repeat="chead options/header" and options/body But maybe you can rething and rephrase your problem :-) ___ 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: Output only the first or a particular record using TAL
Julian Yap wrote: I used the following and it works great (without some formatting for clarity): Customer: hmm, this strikes me as just plain wrong :-S Why is getCustomerLicenses returning more than one row if you only want the first one? If it only returned one row, then you could do: Customer: ...no need for the condition or the yucky integer indexes. Now, if you really can't stop your sql returning more than one row (LIMIT 1 anyone?) then how about: Customer: cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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: Output only the first or a particular record using TAL
Thanks Tres, Sascha and Jirka for your help. I used the following and it works great (without some formatting for clarity): Customer: The above condition checks that 'customer' is not empty. I think I'll need to do some more reading up on "path expressions" and "python expressions". Still mentally confusing to me. Julian ___ 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: Output only the first or a particular record using TAL
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Julian Yap wrote: > Hi all, > > I wanted to create something of a header using TAL and a Z SQL Method. > > I have the following code where getCustomerLicenses is my Z SQL Method and > it prints out the customer's full name with details: > > full_name > serial_number > > > > In it's simplest form, how do I retrieve just the full_name of the first > record using TAL. I think I use tal:replace but I'm not sure. > > I was along the lines of something like this: > > You can use 'tal:condition repeat/licenses/start' to test that you are in the first pass through the loop. Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDKAqD+gerLs4ltQ4RAhKEAJsFo4Tm2DLiUTCSEjcqDUxgVvfsrQCffiyP hXXtC8lu3xbW20JY0RVXOyg= =j0u0 -END PGP SIGNATURE- ___ 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 )