Merge lp:~stevenk/launchpad/one-recipe-redirect into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Leonard Richardson
Approved revision: no longer in the source branch.
Merged at revision: 12258
Proposed branch: lp:~stevenk/launchpad/one-recipe-redirect
Merge into: lp:launchpad
Diff against target: 79 lines (+25/-0)
3 files modified
lib/lp/code/browser/sourcepackagerecipelisting.py (+8/-0)
lib/lp/code/browser/tests/test_recipebuildslisting.py (+11/-0)
lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py (+6/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/one-recipe-redirect
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+47005@code.launchpad.net

Commit message

[r=leonardr][ui=none][bug=704080] If there is only one recipe for a product/person, redirect straight to their recipe.

Description of the change

If there is only one recipe for a product/person, redirect straight to the recipe rather than a listing of recipes.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/sourcepackagerecipelisting.py'
2--- lib/lp/code/browser/sourcepackagerecipelisting.py 2011-01-13 23:09:48 +0000
3+++ lib/lp/code/browser/sourcepackagerecipelisting.py 2011-01-22 00:15:29 +0000
4@@ -15,6 +15,7 @@
5
6 from canonical.launchpad.browser.feeds import FeedsMixin
7 from canonical.launchpad.webapp import (
8+ canonical_url,
9 LaunchpadView,
10 Link,
11 )
12@@ -47,6 +48,13 @@
13 return 'Source Package Recipes for %(displayname)s' % {
14 'displayname': self.context.displayname}
15
16+ def initialize(self):
17+ super(RecipeListingView, self).initialize()
18+ recipes = self.context.getRecipes()
19+ if recipes.count() == 1:
20+ recipe = recipes.one()
21+ self.request.response.redirect(canonical_url(recipe))
22+
23
24 class BranchRecipeListingView(RecipeListingView):
25
26
27=== modified file 'lib/lp/code/browser/tests/test_recipebuildslisting.py'
28--- lib/lp/code/browser/tests/test_recipebuildslisting.py 2011-01-13 23:47:34 +0000
29+++ lib/lp/code/browser/tests/test_recipebuildslisting.py 2011-01-22 00:15:29 +0000
30@@ -13,6 +13,7 @@
31 find_tag_by_id,
32 )
33 from canonical.launchpad.webapp.interfaces import ILaunchpadRoot
34+from canonical.launchpad.webapp.publisher import canonical_url
35 from canonical.testing.layers import DatabaseFunctionalLayer
36 from lp.testing import (
37 ANONYMOUS,
38@@ -191,3 +192,13 @@
39 text = extract_text(row)
40 view_records_text.add(text.replace(' ', '').replace('\n', ''))
41 self.assertEquals(records_text, view_records_text)
42+
43+ def test_one_recipe_redirects_to_recipe_page(self):
44+ # Ensure that if the product or person has only one recipe, they are
45+ # redirected right to the recipe page.
46+ recipe = self.factory.makeSourcePackageRecipe()
47+ root_url = self.layer.appserver_root_url(facet='code')
48+ recipes_url = '%s/~%s/+recipes' % (root_url, recipe.owner.name)
49+ expected_url = canonical_url(recipe)
50+ browser = self.getUserBrowser(recipes_url)
51+ self.assertEquals(expected_url, browser.url)
52
53=== modified file 'lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py'
54--- lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py 2010-10-04 19:50:45 +0000
55+++ lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py 2011-01-22 00:15:29 +0000
56@@ -15,8 +15,11 @@
57 layer = DatabaseFunctionalLayer
58
59 def test_project_branch_recipe_listing(self):
60+ # We can see recipes for the product. We need to create two, since
61+ # only one will redirect to that recipe.
62 branch = self.factory.makeProductBranch()
63 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])
64+ recipe2 = self.factory.makeSourcePackageRecipe(branches=[branch])
65 text = self.getMainText(recipe.base_branch, '+recipes')
66 self.assertTextMatchesExpressionIgnoreWhitespace("""
67 Source Package Recipes for lp:.*
68@@ -24,8 +27,11 @@
69 generic-string.* Person-name""", text)
70
71 def test_package_branch_recipe_listing(self):
72+ # We can see recipes for the package. We need to create two, since
73+ # only one will redirect to that recipe.
74 branch = self.factory.makePackageBranch()
75 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])
76+ recipe2 = self.factory.makeSourcePackageRecipe(branches=[branch])
77 text = self.getMainText(recipe.base_branch, '+recipes')
78 self.assertTextMatchesExpressionIgnoreWhitespace("""
79 Source Package Recipes for lp:.*