[Grok-dev] Re: Grok Widgets / Fields (Was Re: Re: [grok-br] Grok
1.0 and beyond)
daniel
daniel.carraher at gmail.com
Fri Jan 11 03:18:06 EST 2008
So is this a good time to ask for a schema + formlib how-to for Grok?
:)
On Jan 11, 2008 2:15 AM, Luciano Ramalho <luciano at ramalho.org> wrote:
> On Jan 10, 2008 1:37 PM, Sebastian Ware <sebastian at urbantalk.se> wrote:
> > I use formlib but never got into using a form template. Instead I went
> > for the simple solution, where I iterate over the widgets and use
> > widget() to generate each individual widget. Something like this:
> >
> > outp = '<form class="edit-form" enctype="multipart/form-data"
> > method="post" action="" accept-charset="UTF-8">\r'
> > outp += '<table>'
> > for widget in self.widgets:
> > outp += '<tr class="row">\r'
> > outp += '<td class="label"><label for="' + widget.name +
> > '" title="' + widget.hint + '">'
> > outp += widget.label + '</label></td>\r'
> > outp += '<td class="field">' + widget() + '</td>\r'
> > if widget.error() is not None:
> > outp += '<td class="error">' + widget.error() + '</td>
> > \r'
> > else: outp += '<td></td>\r'
> > outp += '</tr>\r'
> > outp += '</table>'
> > outp += '</form>'
> >
> > Mvh Sebastian
>
> Sebastian, the code in default_edit_form.pt also iterates over the
> widgets to render them, it just does so using tal:repeat, not Python
> code.
>
> BTW, you may be interested to know that your use of string
> concatenation to build a page is highly inefficient. Python strings
> are immutable, which means that the += operator is always copying the
> entire string from one place in memory to another, over and over
> again. If you must build long strings like this, a good practice is to
> use a list, and then instead of the += do list.append() for each new
> string segment. Then when everything is appended, you can do a
> ''.join(list) to transform the list of strings into one big string.
> This is much faster.
>
> Of course, the best practice for generating HTML is not to use Python
> at all, but a template language such as ZPT or Genshi.
>
> Regards,
>
> Luciano
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
--
-- Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20080111/62037156/attachment.htm
More information about the Grok-dev
mailing list