launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #04362
Re: Best way to fix canonical_url
On August 18, 2010, Tim Penhey wrote:
> On Thu, 19 Aug 2010 07:52:51 Curtis Hovey wrote:
> > On Thu, 2010-08-19 at 07:25 +1200, Tim Penhey wrote:
> > > It isn't just in unit tests, but in page tests too.
> > >
> > >
> > >
> > > the TALES expression branch/fmt:link/+edit
> > >
> > >
> > >
> > > gets converted to:
> > > canonical_url(branch, view_name="+edit")
> > >
> > >
> > > And we do use that type of TALES expression all over the place.
> >
> >
> >
> > I think you can pass the vhost (not layer) to the tales formatter. This
> > branch/fmt:link:code/+edit
>
> Unfortunately this still hits the same bug. That gets translated to:
>
> canonical_url(branch, rootsite="code", view_name="+edit")
>
> However the rootsite override happens after the view lookup, which uses
> the current browser request.
Ah, now I understand the problem!
You are right, the problem is that the view check is made with the current
request, but there is no guarantee that the request for the link will be on
the same layer than the current one.
So I'd suggest creating a fake request for the lookup which provides the layer
associated to the rootsite. An easy way to do that would be just to register
the layers in ZCML as a utility with the name of the rootsite.
That way you'd do something like:
fake_request = LaunchpadTestRequest()
layer = getUtility(Interface, name=rootside)
zope.component.directlyProvides(fake_request, layer)
and use that fake request in the call to getMultiAdapter.
But if mwhudson proposed solution has other benefit, go for it.
--
Francis J. Lacoste
francis.lacoste@xxxxxxxxxxxxx
Attachment:
signature.asc
Description: This is a digitally signed message part.
Follow ups
References