Hi, hmm, I overlooked this in the docs. So the method name is taken as the view_name? Couldn't find this in the docs.
But I'm still having some trouble with it. I have something like this:
@view_defaults(context=A, name='update')
class UpdateHandler(object):
...
@view_config(predicates...)
def update1(self):
...
@view_config(context=B, predicates...)
def update2(self):
...
When I leave out the "context=B" it works, but when I put it in the
update1 view is not found anymore. I think the context=B overwrites the
context of the whole class, is that possible??
Though maybe I still go for extending this behaviour (I also would like
to have a general cleanup() method in my handler without having to call
it). So is a view_mapper the right way to do this?
Cheers,
Benjamin
On 2/3/12 11:07 PM, Michael Merickel wrote:
> @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
>>
>>
>
signature.asc
Description: OpenPGP digital signature
