<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random Musings of an Insane Mind &#187; tableform</title>
	<atom:link href="http://cd34.com/blog/tag/tableform/feed/" rel="self" type="application/rss+xml" />
	<link>http://cd34.com/blog</link>
	<description>This is my blog, there are many others like it but this one is mine.</description>
	<lastBuildDate>Tue, 29 Jun 2010 04:22:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>TurboGears, Tableform and a callable option to a Widget</title>
		<link>http://cd34.com/blog/programming/python/turbogears-tableform-and-a-callable-option-to-a-widget/</link>
		<comments>http://cd34.com/blog/programming/python/turbogears-tableform-and-a-callable-option-to-a-widget/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 16:31:20 +0000</pubDate>
		<dc:creator>cd34</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[tableform]]></category>
		<category><![CDATA[toscawidgets]]></category>
		<category><![CDATA[turbogears]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://cd34.com/blog/?p=641</guid>
		<description><![CDATA[While doing some TurboGears development I ran into an issue where I needed to generate a select field&#8217;s options from the database that was dependent on authentication. Since defining the query in the model results in a cached result when the class is instantiated, the query couldn&#8217;t be defined there. There are multiple mentions of [...]]]></description>
			<content:encoded><![CDATA[<p>While doing some TurboGears development I ran into an issue where I needed to generate a select field&#8217;s options from the database that was dependent on authentication.  Since defining the query in the model results in a cached result when the class is instantiated, the query couldn&#8217;t be defined there.  There are multiple mentions of using a callable to deal with this situation, but, no code example.</p>
<p>From this posting in <a href="http://groups.google.com/group/turbogears/browse_thread/thread/b390280051e0f7d8/">Google Groups for TurboGears</a>, we were able to figure out the code that made this work.</p>
<p>template:</p>
<pre>&lt;div xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="">

${tmpl_context.form(value=value)}

&lt;/div></pre>
<p>controller:</p>
<pre>    @expose('cp.templates.template')
    def form(self):
        c.form = TestForm()
        c.availips = [[3,3],[2,2]]
        return dict(template='form',title='Test Form',value=None)</pre>
<p>model:</p>
<pre>from pylons import c

def get_ips():
    return c.availips

class TestForm(TableForm):
    action = '/test/testadd'
    submit_text = 'Add test'

    class fields(WidgetsList):
        User = TextField(label_text='FTP Username', size=40, validator=NotEmpty())
        Password = PasswordField(label_text='FTP Password', size=40, validator=NotEmpty())
        ip = SingleSelectField(label_text="Assign to IP",options=get_ips)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cd34.com/blog/programming/python/turbogears-tableform-and-a-callable-option-to-a-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
