<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A few rules I try to follow with TurboGears</title>
	<atom:link href="http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/</link>
	<description>Programming, gardening, economics, life in Cleveland Heights</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:03:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: matt</title>
		<link>http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/comment-page-1/#comment-896</link>
		<dc:creator>matt</dc:creator>
		<pubDate>Mon, 17 Mar 2008 18:32:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/#comment-896</guid>
		<description>Christopher  Arndt: Most of the time, I don&#039;t care about coercing into a list in the controller before the template because like you point out, it&#039;s the same cost if I do it in the controller vs the template.

However, in templates where I iterate through the results twice, it does make sense to coerce the selectResults into a list.  Otherwise, I&#039;ll run the exact same query twice:
&lt;code&gt;
In [24]: User.select(User.q.user_name.startswith(&#039;Z&#039;))

Out[24]: &lt;SelectResults at 8f804cc&gt;

In [25]: list(_24)
 1/Select  :  SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))
 1/QueryR  :  SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))

Out[25]: []

In [26]: list(_24)
 1/Select  :  SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))
 1/QueryR  :  SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))

Out[26]: []
&lt;/code&gt;

However, what I really care about is making sure that I don&#039;t follow any multiplejoins or related joins once I&#039;m already in the template.  So instead of doing something like this in my template:
&lt;code&gt;
    for employee in employees:
        for task in employee.tasks: # tasks are a related join, and this does a query every time.
&lt;/code&gt;
I&#039;ll build a dictionary in my controller that maps employees to tasks:
&lt;code&gt;
    for employee in employees;
        for task in employee_tasks[employee]
&lt;/code&gt;

The rule of thumb about making sure everything is already out of the database before I get to the template is just a simple way of avoiding the previous two scenarios.</description>
		<content:encoded><![CDATA[<p>Christopher  Arndt: Most of the time, I don&#8217;t care about coercing into a list in the controller before the template because like you point out, it&#8217;s the same cost if I do it in the controller vs the template.</p>
<p>However, in templates where I iterate through the results twice, it does make sense to coerce the selectResults into a list.  Otherwise, I&#8217;ll run the exact same query twice:<br />
<pre><code>
In [24]: User.select(User.q.user_name.startswith(&#039;Z&#039;))

Out[24]: &lt;SelectResults at 8f804cc&gt;

In [25]: list(_24)
 1/Select&nbsp;&nbsp;:&nbsp;&nbsp;SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))
 1/QueryR&nbsp;&nbsp;:&nbsp;&nbsp;SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))

Out[25]: []

In [26]: list(_24)
 1/Select&nbsp;&nbsp;:&nbsp;&nbsp;SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))
 1/QueryR&nbsp;&nbsp;:&nbsp;&nbsp;SELECT tg_user.id, tg_user.modifieddate, tg_user.createddate, tg_user.supervisor_id, tg_user.first_name, tg_user.last_name, tg_user.v2organization_id, tg_user.participationstatus_id, tg_user.user_name, tg_user.email_address, tg_user.password, tg_user.mobilenumber, tg_user.homenumber FROM tg_user WHERE ((tg_user.user_name) LIKE (&#039;Z%&#039;))

Out[26]: []
</code></pre></p>
<p>However, what I really care about is making sure that I don&#8217;t follow any multiplejoins or related joins once I&#8217;m already in the template.  So instead of doing something like this in my template:<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;for employee in employees:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for task in employee.tasks: # tasks are a related join, and this does a query every time.
</code></pre><br />
I&#8217;ll build a dictionary in my controller that maps employees to tasks:<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;for employee in employees;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for task in employee_tasks[employee]
</code></pre></p>
<p>The rule of thumb about making sure everything is already out of the database before I get to the template is just a simple way of avoiding the previous two scenarios.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Arndt</title>
		<link>http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/comment-page-1/#comment-895</link>
		<dc:creator>Christopher Arndt</dc:creator>
		<pubDate>Mon, 17 Mar 2008 18:18:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/#comment-895</guid>
		<description>Your first rule seems very tough to meet. Wouldn&#039;t that mean that you need to flatten any generator for select results to a list and also do the same for any attribute capsuling a 1:n or n:m-relation?

I don&#039;t see the advantage of this. If you want to see the queries executed by your page controller, turn on SQLObject/SQLAlchemy debugging. Anyway, there&#039;s no real difference between controller and template processing in this respect. They both happen in your controller method, only the template rendering is hidden in the &quot;expose&quot; decorator.</description>
		<content:encoded><![CDATA[<p>Your first rule seems very tough to meet. Wouldn&#8217;t that mean that you need to flatten any generator for select results to a list and also do the same for any attribute capsuling a 1:n or n:m-relation?</p>
<p>I don&#8217;t see the advantage of this. If you want to see the queries executed by your page controller, turn on SQLObject/SQLAlchemy debugging. Anyway, there&#8217;s no real difference between controller and template processing in this respect. They both happen in your controller method, only the template rendering is hidden in the &#8220;expose&#8221; decorator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt</title>
		<link>http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/comment-page-1/#comment-894</link>
		<dc:creator>matt</dc:creator>
		<pubDate>Mon, 17 Mar 2008 15:52:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/#comment-894</guid>
		<description>Chris, thanks for the comments!  If I understand you right, instead of
&lt;code&gt;
    redbirds = classmethod(partial(by_color, color=&#039;red&#039;))
    bluebirds = classmethod(partial(by_color, color=&#039;blue&#039;))
&lt;/code&gt;
I could do:
&lt;code&gt;
    by_color = classmethod(by_color)
    redbirds = partial(by_color, color=&#039;red&#039;)
    bluebirds = partial(by_color, color=&#039;blue&#039;)
&lt;/code&gt;

I haven&#039;t tried it out, but I like that I don&#039;t need to keep using classmethod over and over again in your approach.</description>
		<content:encoded><![CDATA[<p>Chris, thanks for the comments!  If I understand you right, instead of<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;redbirds = classmethod(partial(by_color, color=&#039;red&#039;))
&nbsp;&nbsp;&nbsp;&nbsp;bluebirds = classmethod(partial(by_color, color=&#039;blue&#039;))
</code></pre><br />
I could do:<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;by_color = classmethod(by_color)
&nbsp;&nbsp;&nbsp;&nbsp;redbirds = partial(by_color, color=&#039;red&#039;)
&nbsp;&nbsp;&nbsp;&nbsp;bluebirds = partial(by_color, color=&#039;blue&#039;)
</code></pre></p>
<p>I haven&#8217;t tried it out, but I like that I don&#8217;t need to keep using classmethod over and over again in your approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/comment-page-1/#comment-893</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 17 Mar 2008 12:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/index.php/2008/03/16/a-few-rules-i-try-to-follow-with-turbogears/#comment-893</guid>
		<description>Concerning the sidenote, this is because an unbound classmethod is indeed not callable (it only wraps a callable that you need to __get__ first). A workaround would be adding by_color=classmethod(by_color) at the end of the class declaration.</description>
		<content:encoded><![CDATA[<p>Concerning the sidenote, this is because an unbound classmethod is indeed not callable (it only wraps a callable that you need to __get__ first). A workaround would be adding by_color=classmethod(by_color) at the end of the class declaration.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

