812
=== Absolute links ===
814
Absolute urls can be made with a full url, including the host part, or
815
as a url path beginning with '/'.
817
Sometimes the target will be within Launchpad. Other times, the link
818
will be to an external site.
820
When the link is to a page in Launchpad, we need to treat it the same as
821
a normal relative link. That is, we need to compute 'linked' and
822
'selected' as for relative links. The usual use-case is computing an
823
absolute link to a page inside launchpad using canonical_url. In this
824
case, the host and protocol part of the url will be the same for the
825
canonical_url as for the current request. This is what we will use to
826
see if we have a link to a page within Launchpad.
828
>>> class AbsoluteUrlTargetTestFacets(FacetMenu):
829
... links = ['foo', 'bar', 'baz', 'spoo']
834
... return Link(target, text)
837
... target = 'ftp://barlink.example.com/barbarbar'
838
... text = 'External bar'
839
... return Link(target, text)
842
... target = 'http://launchpad.dev/joy-of-cooking/+baz'
844
... return Link(target, text)
847
... target = '/joy-of-cooking/+spoo'
849
... return Link(target, text)
851
>>> print canonical_url(cookbook)
852
http://launchpad.dev/joy-of-cooking
854
>>> request_url = URI('http://launchpad.dev/joy-of-cooking')
856
>>> facets = AbsoluteUrlTargetTestFacets(cookbook)
857
>>> for link in facets.iterlinks(request_url):
858
... print link.url, link.linked
859
http://launchpad.dev/joy-of-cooking False
860
ftp://barlink.example.com/barbarbar True
861
http://launchpad.dev/joy-of-cooking/+baz True
862
http://launchpad.dev/joy-of-cooking/+spoo True
812
865
==== The current view's menu ====
814
867
The linked state of a link may be determined from the menu adapted