launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #04368
Re: Best way to fix canonical_url
On Wed, 18 Aug 2010 16:48:43 -0400, "Francis J. Lacoste" <francis.lacoste@xxxxxxxxxxxxx> wrote:
>
> On August 18, 2010, Tim Penhey wrote:
> > 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.
I guess my suggestion comes from the fact that we _almost_ have enough
information in the ZCML to create this registry already, and perhaps we
should add the teensy bit more we need, and avoid any risk of skew.
Although, really, rootsites don't get added or changed especially
often...
Cheers,
mwh
Follow ups
References