On Wed, 2010-11-24 at 10:08 -0800, Jeff Dairiki wrote:
> Here's my second question.
>
> URL generation seems awkward when using hybrid URL dispatch &
> traversal.
> I suspect I'm missing something what is it?
>
> I have a route like:
>
> config.add_route('admin', 'admin/*traverse',
> factory='.models.get_admin_root')
>
> and a bunch of views defined with route_name='admin'.
>
> The dispatch is working fine, but I'm having trouble figuring out to
> generate urls.
>
> request.model_url(context)
>
> yields an incorrect URL (no leading /admin in the path.) Route_url()
> can be made to
> work, but takes a bit of work — something like this
>
> def admin_model_url(context, request, *elements, **kwargs):
> options = dict( ('_'+k, v) for k, v in kwargs.iteritems() )
> options['traverse'] = traversal_path(model_path(context))
> return request.route_url('admin', *elements, **options)
>
> (another option would be to adjust request.SCRIPT_NAME, but how do I
> do that every time the 'admin' route matches?)
>
> What am I missing? There must be a simpler way.
I'm afraid not. The admin_model_url you have above is about the right
way to do it. Although I'm not really sure why options is built by
prepending _ to kwargs (but I don't care, in general passing a
"traverse" kwarg containing the path to route_url is the right way to do
this).
- C
--
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.