Hi,

I converted away from handlers to using the match_param view_defaults and
view_config with the match_param option. I found that often enough I wanted
to override the method name as the action that is was no big deal to always
use match_param (since I was very frequently using the name option of the
action decorator). I have a semi fleshed out example below. If you *really*
want to default to the name of the method, then you'll need to write your
own decorator that then calls view_config as you show below. Note that your
example you use matchparam instead of match_param.

config.add_route('someroute_index', 'someroute')
config.add_route('someroute', 'someroute/{action}')

@view_defaults(route_name='someroute')
class SomeView(object):
    def __init__(self, request):
          self.request = request

    @view_config(route_name='someroute_index',
renderer='index_renderer.mak')
    def index(self):
        ....

    @view_config(match_param='action=edit', request_method='POST',
renderer='edit_renderer.mak')
     def save(self):
         ....

    @view_config(match_param='action=edit', renderer='edit_renderer.mak')
     def edit(self):
         ...

     @view_config(match_param='action=jsonaction', renderer='json')
     def json_action(self):
         ...


I also played around with setting up action to allow empty string instead
of using the someaction_index route, but that was pretty annoying in
request.route_path where you would need to do
request.route_path('someroute', action=''), it just ended up looking
cleaner to have a separate route for the "index" condition.

-Chris

On Tue, Aug 28, 2012 at 5:07 PM, Jason <[email protected]> wrote:

> Hello,
>
> I'm trying to move on from pyramid_handlers to using config.add_route and
> view_config for increased configuration options (and I think it will be
> better organized), but there is one throwback I want to keep. Almost all of
> my view-callables will need the view_config option "matchparam={'action':
> <function_name>}" where function_name is the name of the view-callable def.
> What would be the best way to achieve this?
>
> I think I could subclass view_config and override the __call__ method to
> add it as a parameter as seen below, but is this advisable?
>
> class action_config(view_config):
>     def __call__(self, wrapped):
>         self.matchparam = {'action': wrapped.__name__}
>         return view_config.__call__(self, wrapped)
>
>
> Thanks for feedback,
>
> Jason
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/jhpE8lLT7A8J.
> 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.
>



-- 
Christopher Lambacher
[email protected]

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