On Wed, 2010-11-24 at 16:47 -0800, Jeff Dairiki wrote:
> Hi Chris,
>
> Thanks for the answers!
>
> On Wed, Nov 24, 2010 at 03:11:01PM -0500, Chris McDonough wrote:
> > 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).
>
> (The _ prepending is to map model_url()'s query and anchor
> arguments to the _query and _anchor that route_url() expects.
> Popping query and anchor explicitly, and then re-adding them under
> the corrected keys, would be a better solution.)
>
> I suppose one could use a pregenerator__ on the route to mangle route_url's
> so that
>
> request.route_url('admin', context, *elements, **kw)
>
> would give the desired URL. Is that a complete bastardization of the
> pregenerator paradigm, or is that an acceptable plan?
No, that'd likely be fine. Better suggestions welcome though.
- 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.