Am 15.06.2012 um 21:11 schrieb Theron Luhn:

> A lot of times I use the same view for both editing items and making new 
> items.  How can I determine which view name is being called?  I know I'm not 
> explaining myself very well, so to talk in code:
> 
> @view_config(context=Context, name='new', renderer='edit.pt')
> @view_config(context=Context, name='edit', renderer='edit.pt')
> def edit(context, request):
>     if [name is 'edit']:
>         #Load data to edit
>     elif [name is 'new']:
>         #Do something else
>     #Do more stuff

I prefer a class based approach for things like this.  It's a little more code, 
but IMHO has much better readability:

@view_defaults(context=Context, renderer='edit.pt')
class FooViews():
    def __init__(self, context, request):
        self.context = context
        self.request = request

    def do_common_stuff(self):
        # do more stuff

    @view_config(name='new')
    def new(self):
        #Do something else
        self.do_common_stuff()
    
    @view_config(name='edit')
        #Load data to edit
        self.do_common_stuff()


HTH,

Andreas

-- 
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