launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #21382
[Merge] lp:~wgrant/launchpad/related-projects-batching into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/related-projects-batching into lp:launchpad.
Commit message:
Don't limit Person:+related-projects to a single batch.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/related-projects-batching/+merge/316662
Don't limit Person:+related-projects to a single batch.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/related-projects-batching into lp:launchpad.
=== modified file 'lib/lp/registry/browser/person.py'
--- lib/lp/registry/browser/person.py 2016-12-22 16:32:38 +0000
+++ lib/lp/registry/browser/person.py 2017-02-08 02:43:55 +0000
@@ -190,6 +190,7 @@
from lp.registry.mail.notification import send_direct_contact_email
from lp.registry.model.person import get_recipients
from lp.services.config import config
+from lp.services.database.decoratedresultset import DecoratedResultSet
from lp.services.database.sqlbase import flush_database_updates
from lp.services.feeds.browser import FeedsMixin
from lp.services.geoip.interfaces import IRequestPreferredLanguages
@@ -3348,23 +3349,24 @@
A project dict has the following keys: title, url, is_owner,
is_driver, is_bugsupervisor.
"""
- projects = []
- max_projects = self.max_results_to_display
- pillarnames = self._related_projects[:max_projects]
- for pillarname in pillarnames:
- pillar = pillarname.pillar
- project = {}
- project['title'] = pillar.title
- project['url'] = canonical_url(pillar)
- person = self.context
- project['is_owner'] = person.inTeam(pillar.owner)
- project['is_driver'] = person.inTeam(pillar.driver)
- project['is_bug_supervisor'] = False
- if IHasBugSupervisor.providedBy(pillar):
- project['is_bug_supervisor'] = (
- person.inTeam(pillar.bug_supervisor))
- projects.append(project)
- return projects
+ def decorate(pillarnames):
+ projects = []
+ for pillarname in pillarnames:
+ pillar = pillarname.pillar
+ project = {}
+ project['title'] = pillar.title
+ project['url'] = canonical_url(pillar)
+ person = self.context
+ project['is_owner'] = person.inTeam(pillar.owner)
+ project['is_driver'] = person.inTeam(pillar.driver)
+ project['is_bug_supervisor'] = False
+ if IHasBugSupervisor.providedBy(pillar):
+ project['is_bug_supervisor'] = (
+ person.inTeam(pillar.bug_supervisor))
+ projects.append(project)
+ return projects
+ return DecoratedResultSet(
+ self._related_projects, bulk_decorator=decorate)
@cachedproperty
def first_five_related_projects(self):
=== modified file 'lib/lp/registry/browser/tests/test_person.py'
--- lib/lp/registry/browser/tests/test_person.py 2016-12-22 16:32:38 +0000
+++ lib/lp/registry/browser/tests/test_person.py 2017-02-08 02:43:55 +0000
@@ -5,6 +5,7 @@
import doctest
import email
+import re
from textwrap import dedent
import soupmatchers
@@ -1189,15 +1190,26 @@
def setUp(self):
super(TestPersonRelatedProjectsView, self).setUp()
self.user = self.factory.makePerson()
- self.view = create_initialized_view(self.user, '+related-projects')
def test_view_helper_attributes(self):
# Verify view helper attributes.
- self.assertEqual('Related projects', self.view.page_title)
- self.assertEqual('default_batch_size', self.view._max_results_key)
+ view = create_initialized_view(self.user, '+related-projects')
+ self.assertEqual('Related projects', view.page_title)
+ self.assertEqual('default_batch_size', view._max_results_key)
self.assertEqual(
- config.launchpad.default_batch_size,
- self.view.max_results_to_display)
+ config.launchpad.default_batch_size, view.max_results_to_display)
+
+ def test_batching(self):
+ for i in range(10):
+ self.factory.makeProduct(owner=self.user)
+ view = create_initialized_view(self.user, '+related-projects')
+ password_match = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'Next link', 'a',
+ attrs={'href': re.compile(re.escape(
+ '?batch=5&memo=5&start=5'))},
+ text='Next'))
+ self.assertThat(view(), password_match)
class TestPersonRelatedPackagesFailedBuild(TestCaseWithFactory):
Follow ups