Passing tw forms to templates

7 views
Skip to first unread message

Christoph Zwerschke

unread,
Feb 9, 2009, 9:49:58 AM2/9/09
to turbogea...@googlegroups.com
At http://toscawidgets.org/documentation/tw.forms/tutorials/tg2.html I
found the following:

# Passing the form in the return dict is no longer kosher, you can
# set pylons.c.w.form instead and use c.w.form in your template
# (remember to 'import pylons' too)
pylons.c.w.form = model_form

http://turbogears.org/2.0/docs/main/ToscaWidgets/forms.html has
something similar, but without the comment.

pylons.c.form = create_movie_form

Why is passing a form in the return dict of a controller no longer
"kosher"? If it is really a problem, we need more explanations here.
Also, which one is correct/better, pylons.c.form or pylons.c.w.form?
Even more confusing, the template uses tmpl_context resp. tmpl_context.w
instead of the c alias.

-- Christoph

percious

unread,
Feb 9, 2009, 5:47:39 PM2/9/09
to TurboGears Trunk
pylons.c.form is the correct way to pass the form to the template.

I believe you could also import tmpl_context from tg and say:

tmpl_context.form = form.

That would probably be the more TG way of doing things.

The reason we no longer pass the form into the template dictionary is
because it is not data. Therefore we add the form to the template
context which defines how the template should be drawn, not what data
should be displayed. There was a discussion on this a while back if
you search around.

cheers.
-chris

On Feb 9, 7:49 am, Christoph Zwerschke <c...@online.de> wrote:
> Athttp://toscawidgets.org/documentation/tw.forms/tutorials/tg2.htmlI

Paul Johnston

unread,
Feb 10, 2009, 1:54:16 AM2/10/09
to TurboGears Trunk
Hi,

That was a temporary glitch while TW moved to the resource injector
model. Passing widgets through the dict works fine now. In fact, I
decided to make this the recommended approach in the docs, as it's
framework independent.

I think there is merit in a "widget registry" approach, but there's a
bit of work to do this properly. (and probably other, more interesting
things to look at first)

Paul

Christoph Zwerschke

unread,
Feb 10, 2009, 8:38:52 AM2/10/09
to turbogea...@googlegroups.com
percious schrieb:

> The reason we no longer pass the form into the template dictionary is
> because it is not data. Therefore we add the form to the template
> context which defines how the template should be drawn, not what data
> should be displayed. There was a discussion on this a while back if
> you search around.

Ok, I see. It seems the main point is that if you want to use a
controller for both html and json, then passing widgets in the return
dict will be unnecessary and potentially causing problems with
jsonification. So it is a better practice to pass these via the template
context instead. Seems reasonable to me, this should just be better
explained and documented.

-- Christoph

percious

unread,
Feb 10, 2009, 1:27:37 PM2/10/09
to TurboGears Trunk
I agree, and your description hits the nail on the head ;-).

jorge.vargas

unread,
Feb 11, 2009, 10:55:26 AM2/11/09
to turbogea...@googlegroups.com
On Tue, Feb 10, 2009 at 2:54 AM, Paul Johnston <paul...@gmail.com> wrote:
>
> Hi,
>
Hi Paul,


> That was a temporary glitch while TW moved to the resource injector
> model. Passing widgets through the dict works fine now. In fact, I
> decided to make this the recommended approach in the docs, as it's
> framework independent.
>
I though this was not the case. As Christoph points out the
*recommended* way should be to use tg.tmpl_context/pylons.c as passing
widgets to json controllers will be a bad thing, this is specially
important now that .json and .html urls work in TG. I think we should
reconsider commending this on the docs of TW or document it in both TW
and TG.

jorge.vargas

unread,
Feb 11, 2009, 10:58:24 AM2/11/09
to turbogea...@googlegroups.com
made a ticket for it http://trac.turbogears.org/ticket/2201 I think
the above should be the recommended way.

> -- Christoph
>
>
>
>
> >
>

Gustavo Narea

unread,
Feb 11, 2009, 11:01:35 AM2/11/09
to turbogea...@googlegroups.com, jorge.vargas
On Wednesday February 11, 2009 16:55:26 jorge.vargas wrote:
> I though this was not the case. As Christoph points out the
> recommended way should be to use tg.tmpl_context/pylons.c as passing

> widgets to json controllers will be a bad thing, this is specially
> important now that .json and .html urls work in TG. I think we should
> reconsider commending this on the docs of TW or document it in both TW
> and TG.

+1.
--
Gustavo Narea <http://gustavonarea.net/>.

Get rid of unethical constraints! Get freedomware:
http://www.getgnulinux.org/

Reply all
Reply to author
Forward
0 new messages