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
=== modified file 'lib/lp/code/browser/sourcepackagerecipelisting.py'
--- lib/lp/code/browser/sourcepackagerecipelisting.py 2011-01-13 23:09:48 +0000
+++ lib/lp/code/browser/sourcepackagerecipelisting.py 2011-01-22 00:15:29 +0000
@@ -15,6 +15,7 @@
1515
16from canonical.launchpad.browser.feeds import FeedsMixin16from canonical.launchpad.browser.feeds import FeedsMixin
17from canonical.launchpad.webapp import (17from canonical.launchpad.webapp import (
18 canonical_url,
18 LaunchpadView,19 LaunchpadView,
19 Link,20 Link,
20 )21 )
@@ -47,6 +48,13 @@
47 return 'Source Package Recipes for %(displayname)s' % {48 return 'Source Package Recipes for %(displayname)s' % {
48 'displayname': self.context.displayname}49 'displayname': self.context.displayname}
4950
51 def initialize(self):
52 super(RecipeListingView, self).initialize()
53 recipes = self.context.getRecipes()
54 if recipes.count() == 1:
55 recipe = recipes.one()
56 self.request.response.redirect(canonical_url(recipe))
57
5058
51class BranchRecipeListingView(RecipeListingView):59class BranchRecipeListingView(RecipeListingView):
5260
5361
=== modified file 'lib/lp/code/browser/tests/test_recipebuildslisting.py'
--- lib/lp/code/browser/tests/test_recipebuildslisting.py 2011-01-13 23:47:34 +0000
+++ lib/lp/code/browser/tests/test_recipebuildslisting.py 2011-01-22 00:15:29 +0000
@@ -13,6 +13,7 @@
13 find_tag_by_id,13 find_tag_by_id,
14 )14 )
15from canonical.launchpad.webapp.interfaces import ILaunchpadRoot15from canonical.launchpad.webapp.interfaces import ILaunchpadRoot
16from canonical.launchpad.webapp.publisher import canonical_url
16from canonical.testing.layers import DatabaseFunctionalLayer17from canonical.testing.layers import DatabaseFunctionalLayer
17from lp.testing import (18from lp.testing import (
18 ANONYMOUS,19 ANONYMOUS,
@@ -191,3 +192,13 @@
191 text = extract_text(row)192 text = extract_text(row)
192 view_records_text.add(text.replace(' ', '').replace('\n', ''))193 view_records_text.add(text.replace(' ', '').replace('\n', ''))
193 self.assertEquals(records_text, view_records_text)194 self.assertEquals(records_text, view_records_text)
195
196 def test_one_recipe_redirects_to_recipe_page(self):
197 # Ensure that if the product or person has only one recipe, they are
198 # redirected right to the recipe page.
199 recipe = self.factory.makeSourcePackageRecipe()
200 root_url = self.layer.appserver_root_url(facet='code')
201 recipes_url = '%s/~%s/+recipes' % (root_url, recipe.owner.name)
202 expected_url = canonical_url(recipe)
203 browser = self.getUserBrowser(recipes_url)
204 self.assertEquals(expected_url, browser.url)
194205
=== modified file 'lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py'
--- lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py 2010-10-04 19:50:45 +0000
+++ lib/lp/code/browser/tests/test_sourcepackagerecipelisting.py 2011-01-22 00:15:29 +0000
@@ -15,8 +15,11 @@
15 layer = DatabaseFunctionalLayer15 layer = DatabaseFunctionalLayer
1616
17 def test_project_branch_recipe_listing(self):17 def test_project_branch_recipe_listing(self):
18 # We can see recipes for the product. We need to create two, since
19 # only one will redirect to that recipe.
18 branch = self.factory.makeProductBranch()20 branch = self.factory.makeProductBranch()
19 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])21 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])
22 recipe2 = self.factory.makeSourcePackageRecipe(branches=[branch])
20 text = self.getMainText(recipe.base_branch, '+recipes')23 text = self.getMainText(recipe.base_branch, '+recipes')
21 self.assertTextMatchesExpressionIgnoreWhitespace("""24 self.assertTextMatchesExpressionIgnoreWhitespace("""
22 Source Package Recipes for lp:.*25 Source Package Recipes for lp:.*
@@ -24,8 +27,11 @@
24 generic-string.* Person-name""", text)27 generic-string.* Person-name""", text)
2528
26 def test_package_branch_recipe_listing(self):29 def test_package_branch_recipe_listing(self):
30 # We can see recipes for the package. We need to create two, since
31 # only one will redirect to that recipe.
27 branch = self.factory.makePackageBranch()32 branch = self.factory.makePackageBranch()
28 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])33 recipe = self.factory.makeSourcePackageRecipe(branches=[branch])
34 recipe2 = self.factory.makeSourcePackageRecipe(branches=[branch])
29 text = self.getMainText(recipe.base_branch, '+recipes')35 text = self.getMainText(recipe.base_branch, '+recipes')
30 self.assertTextMatchesExpressionIgnoreWhitespace("""36 self.assertTextMatchesExpressionIgnoreWhitespace("""
31 Source Package Recipes for lp:.*37 Source Package Recipes for lp:.*