So is this a good time to ask for a schema + formlib how-to for Grok?<br>:)<br><br><div class="gmail_quote">On Jan 11, 2008 2:15 AM, Luciano Ramalho &lt;<a href="mailto:luciano@ramalho.org">luciano@ramalho.org</a>&gt; wrote:
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Jan 10, 2008 1:37 PM, Sebastian Ware &lt;<a href="mailto:sebastian@urbantalk.se">
sebastian@urbantalk.se</a>&gt; wrote:<br>&gt; I use formlib but never got into using a form template. Instead I went<br>&gt; for the simple solution, where I iterate over the widgets and use<br>&gt; widget() to generate each individual widget. Something like this:
<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; outp = &#39;&lt;form class=&quot;edit-form&quot; enctype=&quot;multipart/form-data&quot;<br>&gt; method=&quot;post&quot; action=&quot;&quot; accept-charset=&quot;UTF-8&quot;&gt;\r&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; outp += &#39;&lt;table&gt;&#39;
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for widget in self.widgets:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;tr class=&quot;row&quot;&gt;\r&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;td class=&quot;label&quot;&gt;&lt;label for=&quot;&#39; + <a href="http://widget.name" target="_blank">
widget.name</a> +<br>&gt; &#39;&quot; title=&quot;&#39; + widget.hint + &#39;&quot;&gt;&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += widget.label + &#39;&lt;/label&gt;&lt;/td&gt;\r&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;td class=&quot;field&quot;&gt;&#39; + widget() + &#39;&lt;/td&gt;\r&#39;
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if widget.error() is not None:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;td class=&quot;error&quot;&gt;&#39; + widget.error() + &#39;&lt;/td&gt;<br>&gt; \r&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else: outp += &#39;&lt;td&gt;&lt;/td&gt;\r&#39;
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;/tr&gt;\r&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;/table&gt;&#39;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outp += &#39;&lt;/form&gt;&#39;<br>&gt;<br>&gt; Mvh Sebastian<br><br></div>Sebastian, the code in default_edit_form.pt also iterates over the
<br>widgets to render them, it just does so using tal:repeat, not Python<br>code.<br><br>BTW, you may be interested to know that your use of string<br>concatenation to build a page is highly inefficient. Python strings<br>
are immutable, which means that the += operator is always copying the<br>entire string from one place in memory to another, over and over<br>again. If you must build long strings like this, a good practice is to<br>use a list, and then instead of the += do 
list.append() for each new<br>string segment. Then when everything is appended, you can do a<br>&#39;&#39;.join(list) to transform the list of strings into one big string.<br>This is much faster.<br><br>Of course, the best practice for generating HTML is not to use Python
<br>at all, but a template language such as ZPT or Genshi.<br><br>Regards,<br><div><div></div><div class="Wj3C7c"><br>Luciano<br>_______________________________________________<br>Grok-dev mailing list<br><a href="mailto:Grok-dev@zope.org">
Grok-dev@zope.org</a><br><a href="http://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">http://mail.zope.org/mailman/listinfo/grok-dev</a><br></div></div></blockquote></div><br><br clear="all"><br>-- <br><br>-- Daniel