On Thu, Apr 7, 2011 at 3:23 PM, akaariai <akaar...@cc.hut.fi> wrote:
> About the read-only forms part of the proposal: read-only forms will
> be easy to implement if the template widget rendering idea will be
> included in core.
>
> For example for SelectMultiple widget the base template is probably
> something like this:
>
> <select multiple="multiple" name="{{name}}" id="{{id}}">
> {% for choice in choices %}
>   {% if choice.selected %}
>       <option selected="selected" value={{choice.value}}>{{choice}}</
> option>
>   {% else %}
>       <option value={{choice.value}}>{{choice}}</option>
>   {% endif %}
> {% endfor %}
> </select>
>
> If you want a read-only widget, just give it a custom template:
>
> <ul id="{{id}}">
> {% for choice in choices %}
>    {% if choice.selected %}
>        <li>{{choice}}</li>
>    {% endif %}
> {% endfor %}
> </ul>
>
> Now, that was easy :) Combined with template based form rendering, it
> would be relatively easy to implement read-only forms. Another reason
> why template based form/widget rendering would be nice to have in
> core.
>
> By the way, it would be nice to see how the template based rendering
> compares to python based rendering in performance terms when rendering
> a larger list of choices. But on the other hand, if you have a large
> Select/SelectMultiple list there is bound to be some usability issues,
> so maybe the performance isn't that important... Sorry for bringing
> performance up here again, but I am a speed freak :)

If you want to play with template-based widgets and benchmarks, feel
free to look at my github fork [0]. This is where I'm implementing
template-based widgets (http://code.djangoproject.com/ticket/15667)
and I added a few metrics in the last & only commit message. Timing
the forms regressiontests gives this (network calls excluded):

 * No template caching: Ran 402 tests in 2.395s
 * Template caching: Ran 402 tests in 1.413s
 * Old string-based method: Ran 402 tests in 0.864s

If you're interested in measuring the impacts in more details, feel
free to dig and write benchmarks. I'm sure this would result in some
valuable information. I haven't converted the admin widgets yet but
measuring the effect on the admin test suite would also show the
impact on real-world applications.

Bruno

[0] https://github.com/brutasse/django/commits/15667-template-widgets

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to