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 <<a href="mailto:luciano@ramalho.org">luciano@ramalho.org</a>> 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 <<a href="mailto:sebastian@urbantalk.se">
sebastian@urbantalk.se</a>> wrote:<br>> I use formlib but never got into using a form template. Instead I went<br>> for the simple solution, where I iterate over the widgets and use<br>> widget() to generate each individual widget. Something like this:
<br>><br>> outp = '<form class="edit-form" enctype="multipart/form-data"<br>> method="post" action="" accept-charset="UTF-8">\r'<br>> outp += '<table>'
<br>> for widget in self.widgets:<br>> outp += '<tr class="row">\r'<br>> outp += '<td class="label"><label for="' + <a href="http://widget.name" target="_blank">
widget.name</a> +<br>> '" title="' + widget.hint + '">'<br>> outp += widget.label + '</label></td>\r'<br>> outp += '<td class="field">' + widget() + '</td>\r'
<br>> if widget.error() is not None:<br>> outp += '<td class="error">' + widget.error() + '</td><br>> \r'<br>> else: outp += '<td></td>\r'
<br>> outp += '</tr>\r'<br>> outp += '</table>'<br>> outp += '</form>'<br>><br>> 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>''.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