When defining a route, there are several hooks available to you to
configure custom behaviors.
1) The route pattern.
2) Route predicates.
3) Route factory.
You basically touched on all of these in your examples. It's usually
advantageous to have a single route, so let's ignore the pattern
options. Similarly you can do custom code in the predicates but that's
shoe-horning side-effects into the predicates which is not a good
match.
I'd recommend using a factory specific to that route. You can do cool
things in that factory like inspect/modify the matchdict. Views
attached to that route can then still expect a particular format for
the matchdict and even define *view* predicates that dispatch to
different views based on the matchdict.
On the flip side you can use a pregenerator on that route to make
generation easy. For example, request.route_url('by', userid=50) and
request.route_url('by', username='bob') would both invoke the
pregenerator that inspects the kwargs and converts
kwargs['identifier'] = '-' + kwargs.pop(userid) versus
kwargs['identifier'] = kwargs.pop('username').
Anyway I think you already know how to solve your problem so my ideas
may just reinforce what you were already thinking.
- Michael
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
pylons-discus...@googlegroups.com.
> To post to this group, send email to
pylons-...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/pylons-discuss.
> For more options, visit
https://groups.google.com/d/optout.