Merge lp:~salgado/launchpad/real-breadcrumbs into lp:launchpad

Proposed by Guilherme Salgado
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/real-breadcrumbs
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~salgado/launchpad/real-breadcrumbs
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+10651@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

= Summary =

The Breadcrumb adapter doesn't honor the rootsite specified in ICanonicalUrlData

== Proposed fix ==

Change Breadcrumb.rootsite into a property that looks for a rootsite for
its given object in the ICanonicalUrlData of that object, falling back
to 'mainsite' if it's not defined for that object.

This is a fix for bug 418214

== Tests ==

./bin/test -vvt test_breadcrumbs

== Demo and Q/A ==

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py
  lib/canonical/launchpad/webapp/breadcrumb.py
  lib/lp/bugs/browser/bugtask.py

== Pylint notices ==

lib/lp/bugs/browser/bugtask.py
    1232: [C0301] Line too long (79/78)
    92: [F0401] Unable to import 'lazr.uri' (No module named uri)

Revision history for this message
Graham Binns (gmb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/webapp/breadcrumb.py'
2--- lib/canonical/launchpad/webapp/breadcrumb.py 2009-08-24 17:47:34 +0000
3+++ lib/canonical/launchpad/webapp/breadcrumb.py 2009-08-25 12:35:23 +0000
4@@ -15,7 +15,8 @@
5 from zope.interface import implements
6
7 from canonical.launchpad.webapp import canonical_url
8-from canonical.launchpad.webapp.interfaces import IBreadcrumb
9+from canonical.launchpad.webapp.interfaces import (
10+ IBreadcrumb, ICanonicalUrlData)
11
12
13 class Breadcrumb:
14@@ -25,13 +26,25 @@
15 """
16 implements(IBreadcrumb)
17
18- rootsite = 'mainsite'
19 text = None
20
21 def __init__(self, context):
22 self.context = context
23
24 @property
25+ def rootsite(self):
26+ """The rootsite of this breadcrumb's URL.
27+
28+ If the `ICanonicalUrlData` for our context defines a rootsite, we
29+ return that, otherwise we return 'mainsite'.
30+ """
31+ url_data = ICanonicalUrlData(self.context)
32+ if url_data.rootsite:
33+ return url_data.rootsite
34+ else:
35+ return 'mainsite'
36+
37+ @property
38 def url(self):
39 return canonical_url(self.context, rootsite=self.rootsite)
40
41
42=== modified file 'lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py'
43--- lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py 2009-08-20 19:22:20 +0000
44+++ lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py 2009-08-25 12:35:23 +0000
45@@ -5,10 +5,36 @@
46
47 import unittest
48
49+from zope.interface import implements
50+
51+from canonical.launchpad.webapp.breadcrumb import Breadcrumb
52+from canonical.launchpad.webapp.interfaces import ICanonicalUrlData
53 from canonical.launchpad.webapp.publisher import canonical_url
54 from canonical.launchpad.webapp.tests.breadcrumbs import (
55 BaseBreadcrumbTestCase)
56-from lp.testing import login
57+from lp.testing import login, TestCase
58+
59+
60+class Cookbook:
61+ implements(ICanonicalUrlData)
62+ rootsite = None
63+
64+
65+class TestBreadcrumb(TestCase):
66+
67+ def test_rootsite_defaults_to_mainsite(self):
68+ # When a class' ICanonicalUrlData doesn't define a rootsite, our
69+ # Breadcrumb adapter will use 'mainsite' as the rootsite.
70+ cookbook = Cookbook()
71+ self.assertIs(cookbook.rootsite, None)
72+ self.assertEquals(Breadcrumb(cookbook).rootsite, 'mainsite')
73+
74+ def test_urldata_rootsite_is_honored(self):
75+ # When a class' ICanonicalUrlData defines a rootsite, our Breadcrumb
76+ # adapter will use it.
77+ cookbook = Cookbook()
78+ cookbook.rootsite = 'cooking'
79+ self.assertEquals(Breadcrumb(cookbook).rootsite, 'cooking')
80
81
82 class TestExtraVHostBreadcrumbsOnHierarchyView(BaseBreadcrumbTestCase):
83
84=== modified file 'lib/lp/bugs/browser/bugtask.py'
85--- lib/lp/bugs/browser/bugtask.py 2009-08-24 20:28:33 +0000
86+++ lib/lp/bugs/browser/bugtask.py 2009-08-25 12:35:23 +0000
87@@ -3514,8 +3514,6 @@
88 class BugTaskBreadcrumb(Breadcrumb):
89 """Breadcrumb for an `IBugTask`."""
90
91- rootsite = 'bugs'
92-
93 def __init__(self, context):
94 super(BugTaskBreadcrumb, self).__init__(context)
95 # If the user does not have permission to view the bug for
96