<?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>Yann's Blog &#187; yyafl</title>
	<atom:link href="http://yannramin.com/category/software/yyafl/feed/" rel="self" type="application/rss+xml" />
	<link>http://yannramin.com</link>
	<description>Software and life</description>
	<lastBuildDate>Wed, 07 Jul 2010 20:04:59 +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>yyafl 0.2.1 is now available</title>
		<link>http://yannramin.com/2009/01/22/yyafl-021-is-now-available/</link>
		<comments>http://yannramin.com/2009/01/22/yyafl-021-is-now-available/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 05:59:19 +0000</pubDate>
		<dc:creator>Yann</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[yyafl]]></category>

		<guid isPermaLink="false">http://yannramin.com/?p=140</guid>
		<description><![CDATA[yyafl, a Python web form library operating on domain objects, now has version 0.2.1 available for download. This release includes numerous fixes for decorators, including the ability to attach multiple decorators to a form field or the wildcard &#8216;*&#8217; field. An example is given below, in the context of a CherryPy handler. This example is [...]]]></description>
			<content:encoded><![CDATA[<p><b>yyafl</b>, a <a href="http://python.org">Python</a> web form library operating on domain objects, now has version <i>0.2.1</i> available for download. This release includes numerous fixes for decorators, including the ability to attach multiple decorators to a form field or the wildcard &#8216;*&#8217; field. </p>
<p>An example is given below, in the context of a <a href="http://www.cherrypy.org">CherryPy handler</a>. This example is available in the download as
<pre>examples/layout02.py</pre>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> cherrypy
<span style="color: #ff7700;font-weight:bold;">import</span> yyafl
<span style="color: #ff7700;font-weight:bold;">import</span> yyafl.<span style="color: black;">layout</span>
<span style="color: #ff7700;font-weight:bold;">from</span> yyafl <span style="color: #ff7700;font-weight:bold;">import</span> fields
<span style="color: #ff7700;font-weight:bold;">from</span> yyafl.<span style="color: black;">widgets</span> <span style="color: #ff7700;font-weight:bold;">import</span> HiddenInput
&nbsp;
<span style="color: #808080; font-style: italic;"># This example covers the user of custom decorators for required form fields</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Form1<span style="color: black;">&#40;</span>yyafl.<span style="color: black;">Form</span><span style="color: black;">&#41;</span>:
    name = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>label = <span style="color: #483d8b;">&quot;User name&quot;</span>, required = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">email</span> = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>label = <span style="color: #483d8b;">&quot;Your e-mail address&quot;</span>, required = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    optional = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>label = <span style="color: #483d8b;">&quot;Optional field&quot;</span>, required = <span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    hidden = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>widget = HiddenInput, default = <span style="color: #483d8b;">&quot;123&quot;</span><span style="color: black;">&#41;</span>
    _layout = yyafl.<span style="color: black;">layout</span>.<span style="color: black;">TableLayout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> RequiredDecorator<span style="color: black;">&#40;</span>yyafl.<span style="color: black;">layout</span>.<span style="color: black;">NullDecorator</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; Draw a * next to all required fields &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> extra_markup_widget<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, field, rendered_text<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> field.<span style="color: black;">required</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> rendered_text + <span style="color: #483d8b;">&quot; * &quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> rendered_text
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> FormTest<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    @cherrypy.<span style="color: black;">expose</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> index<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
        f = Form1<span style="color: black;">&#40;</span>data = kwargs<span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># Add a global decorator</span>
        f.<span style="color: black;">layout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">add_decorator</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'*'</span>, RequiredDecorator<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        content = <span style="color: #483d8b;">&quot;&quot;</span>
        content += <span style="color: #483d8b;">&quot;&lt;html&gt;&lt;body&gt;&quot;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> f.<span style="color: black;">is_valid</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #008000;">False</span>:
            content += <span style="color: #483d8b;">&quot;Errors: &quot;</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> error <span style="color: #ff7700;font-weight:bold;">in</span> f.<span style="color: black;">errors</span>:
                content += error + <span style="color: #483d8b;">&quot; : &quot;</span> + f.<span style="color: black;">errors</span><span style="color: black;">&#91;</span>error<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;&lt;br /&gt;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> f.<span style="color: black;">is_bound</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> f.<span style="color: black;">is_valid</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            content += <span style="color: #483d8b;">&quot;Thanks for the data!&quot;</span>
&nbsp;
&nbsp;
        content += <span style="color: #483d8b;">&quot;&lt;p&gt;&lt;form method=<span style="color: #000099; font-weight: bold;">\&quot;</span>GET<span style="color: #000099; font-weight: bold;">\&quot;</span> action=<span style="color: #000099; font-weight: bold;">\&quot;</span>/<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Render using the layout specified in _layout above.</span>
        content += f.<span style="color: black;">render</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># Or invoke the layout explicitly</span>
        <span style="color: #808080; font-style: italic;"># l = yyafl.layout.TableLayout()</span>
        <span style="color: #808080; font-style: italic;"># l.render(f)</span>
&nbsp;
        content += <span style="color: #483d8b;">&quot;&lt;br /&gt; &lt;input type='submit' value='Submit' /&gt;&lt;/form&gt;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> content
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    cherrypy.<span style="color: black;">quickstart</span><span style="color: black;">&#40;</span>root = FormTest<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://yannramin.com/2009/01/22/yyafl-021-is-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>yyafl now has layout support, with decorators</title>
		<link>http://yannramin.com/2008/09/29/yyafl-now-has-layout-support-with-decorators/</link>
		<comments>http://yannramin.com/2008/09/29/yyafl-now-has-layout-support-with-decorators/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 07:35:17 +0000</pubDate>
		<dc:creator>Yann</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[yyafl]]></category>

		<guid isPermaLink="false">http://yannramin.com/?p=103</guid>
		<description><![CDATA[Just finished adding in a flexible layout system to yyafl, my reimplementation of Django newforms for other Python web frameworks or WSGI adapters. Now its simple to add default layouts or render a different layout on demand. For example, to add a simple TableLayout() to a form: class Form1&#40;yyafl.Form&#41;: name = fields.CharField&#40;label = &#34;User name&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Just finished adding in a flexible layout system to <a href="http://www.stackfoundry.com/yyafl/">yyafl</a>, my reimplementation of Django newforms for other Python web frameworks or WSGI adapters. Now its simple to add default layouts or render a different layout on demand.</p>
<p>For example, to add a simple TableLayout() to a form:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Form1<span style="color: black;">&#40;</span>yyafl.<span style="color: black;">Form</span><span style="color: black;">&#41;</span>:
    name = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>label = <span style="color: #483d8b;">&quot;User name&quot;</span>, required = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">email</span> = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>label = <span style="color: #483d8b;">&quot;Your e-mail address&quot;</span>, required = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    hidden = fields.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>widget = HiddenInput, default = <span style="color: #483d8b;">&quot;123&quot;</span><span style="color: black;">&#41;</span>
    _layout = yyafl.<span style="color: black;">layout</span>.<span style="color: black;">TableLayout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>and to render the form to HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Render using the layout specified in _layout above.</span>
content += f.<span style="color: black;">render</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;"># Or invoke the layout explicitly</span>
l = yyafl.<span style="color: black;">layout</span>.<span style="color: black;">TableLayout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
content += l.<span style="color: black;">render</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></pre></div></div>

<p>yyafl Layout()s also understand decorators:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">decorators = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'*'</span> : MarkRequiredDecorator<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
    <span style="color: #483d8b;">'name_field'</span> : HighlightDecorator<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#125;</span>
layout = yyafl.<span style="color: black;">layout</span>.<span style="color: black;">TableLayout</span><span style="color: black;">&#40;</span>decorators = decorators<span style="color: black;">&#41;</span>
layout.<span style="color: black;">render</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></pre></div></div>

<p>Decorators can change attributes and wrap fields in markup blocks. In the above example, the &#8216;*&#8217; signifies the decorator should apply to all fields, and the HighlightDecorator should only apply to the field called &#8216;name_field&#8217;.</p>
<p>There are still some not yet implemented ideas:</p>
<ul>
<li>It doesn&#8217;t generated the &lt;form&gt; blocks yet, you need to roll your own.</li>
<li>Field reordering and grouping isn&#8217;t supported by the default layout engines yet, though you could write your own.</li>
<li>No AJAX form support (though its coming!)</li>
<li>Automatic CSRF prevention forms. </li>
<li>Error message printing in the form.</li>
</ul>
<p>You can find these latest changes in the Git repository linked from the <a href="http://www.stackfoundry.com/yyafl/">main yyafl web page.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yannramin.com/2008/09/29/yyafl-now-has-layout-support-with-decorators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.358 seconds -->
