@view_defaults(context=..)
class ViewHandler(object):
    def __init__(self, context, request):
        # do stuff

    @view_config(renderer='myview.mako')
    def view(self):
        # do stuff for name='view'

    @view_config(renderer='myedit.mako')
    def edit(self):
        # do stuff for name='edit'

Note that prior to 1.3a6 you cannot use @view_defaults so you'll have to
just move the context and other common parameters into each individual
@view_config call.

On Fri, Feb 3, 2012 at 2:47 PM, Benjamin Hepp
<[email protected]>wrote:

> Hi,
>
> is there something similar to pyramid_handlers for traversal but instead
> using the view name?
>
> I would like to do something like this:
>
> @view_config(context=Foo, ...)
> class ViewHandler(object):
>    def __init__(self, context, request):
>        self.context = context
>        self.request = request
>        # do some processing
>
>    def view(self):
>        # process requests with view_name='view'
>
>    def edit(self):
>        # process requests with view_name='edit'
>
> Because I have some common processing and this way I wouldn't have to
> call do_processing(context, request) or whatever in every view handler
> method.
>
> If there is nothing like this available, what do you think about it?
> Would you rather go for decorating all the methods directly?
>
> I guess the "right" way to implement this would be with a view mapper,
> right? But how can I register a view for all view_names?
>
> Cheers,
> Benjamin
>
>

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

Reply via email to