← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/one-recipe-redirect into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #704080 If there is only one recipe, it should redirect right to the recipe
  https://bugs.launchpad.net/bugs/704080

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/one-recipe-redirect/+merge/47005

If there is only one recipe for a product/person, redirect straight to the recipe rather than a listing of recipes.
-- 
https://code.launchpad.net/~stevenk/launchpad/one-recipe-redirect/+merge/47005
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/one-recipe-redirect into lp:launchpad.
=== 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-21 00:11:17 +0000
@@ -15,6 +15,7 @@
 
 from canonical.launchpad.browser.feeds import FeedsMixin
 from canonical.launchpad.webapp import (
+    canonical_url,
     LaunchpadView,
     Link,
     )
@@ -47,6 +48,13 @@
         return 'Source Package Recipes for %(displayname)s' % {
             'displayname': self.context.displayname}
 
+    def initialize(self):
+        super(RecipeListingView, self).initialize()
+        recipes = self.context.getRecipes()
+        if recipes.count() == 1:
+            recipe = recipes.one()
+            self.request.response.redirect(canonical_url(recipe))
+
 
 class BranchRecipeListingView(RecipeListingView):
 

=== 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-21 00:11:17 +0000
@@ -13,6 +13,7 @@
     find_tag_by_id,
     )
 from canonical.launchpad.webapp.interfaces import ILaunchpadRoot
+from canonical.launchpad.webapp.publisher import canonical_url
 from canonical.testing.layers import DatabaseFunctionalLayer
 from lp.testing import (
     ANONYMOUS,
@@ -191,3 +192,13 @@
             text = extract_text(row)
             view_records_text.add(text.replace(' ', '').replace('\n', ''))
         self.assertEquals(records_text, view_records_text)
+
+    def test_one_recipe_redirects_to_recipe_page(self):
+        # Ensure that if the product or person has only one recipe, they are
+        # redirected right to the recipe page.
+        recipe = self.factory.makeSourcePackageRecipe()
+        root_url = self.layer.appserver_root_url(facet='code')
+        recipes_url = '%s/~%s/+recipes' % (root_url, recipe.owner.name)
+        expected_url = canonical_url(recipe)
+        browser = self.getUserBrowser(recipes_url)
+        self.assertEquals(expected_url, browser.url)