This may help you:

http://stackoverflow.com/questions/6553569/in-pyramid-how-can-i-use-a-different-renderer-based-on-contents-of-context/6557728#6557728

On top of that, pyramid also supports:

request.override_renderer = ...

via

http://docs.pylonsproject.org/projects/pyramid/1.1/narr/renderers.html#overriding-a-renderer-at-runtime

On Thu, Aug 4, 2011 at 8:57 AM, neurino <neur...@gmail.com> wrote:

> Is there a *suggested* way to set a view renderer at runtime in
> Pyramid?
>
> What I need is to render, in the same view, a basic form then, if some
> more info are needed (this is known by first form data), render
> another form with already entered info as hidden field and more fields
> to be filled.
>
> In a Pylons controller I could select which renderer use like this:
>
> def my_view(self):
>    c.form = Form(request, BasicSchema)
>    if c.form.validate():
>        obj = form.bind(MYModel())
>        if **need more info**:
>            c.form = Form(AdvancedSchema, obj=obj)
>            if form.validate():
>                obj = form.bind(obj)
>            else:
>                return render('advanced_form.mako')
>        **persist obj someway**
>        redirect(...)
>    return render('basic_form.mako')
>
> In my Pyramid app I have:
>
> config.add_route('new', '/new')
> config.add_view(my_view, route_name='new',
>    renderer='basic_form.mako')
>
> and in `basic_form.mako` according to a passed value I render the form
> one way or another:
>
> %if step == 1:
>    #render basic form
> %else:
>    #render advanced form
> %endif
>
> but it seems a bit ugly and cumbersome to me.
>
> Any advice?
>
> Thanks for your support
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>


-- 

Michael

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

Reply via email to