Skip to content

Commit

Permalink
Add "max" query parameter for get_recently_added_contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Nov 18, 2014
1 parent d10de50 commit 6d5d909
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_contributors_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,14 @@ def test_get_recently_added_contributors(self):
project.reload()
recent = [c for c in self.user.recently_added if c.is_active()]
assert_equal(len(res.json['contributors']), len(recent))


def test_get_recently_added_contributors_with_limit(self):
project = ProjectFactory(creator=self.user)
for _ in range(5):
project.add_contributor(AuthUserFactory(), auth=self.auth)
project.save()
url = self.project.api_url_for('get_recently_added_contributors', max=4)
res = self.app.get(url, auth=self.user.auth)
project.reload()
assert_equal(len(res.json['contributors']), 4)
11 changes: 10 additions & 1 deletion website/project/views/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,18 @@ def get_most_in_common_contributors(auth, **kwargs):
def get_recently_added_contributors(auth, **kwargs):
node = kwargs['node'] or kwargs['project']

try:
max_results = int(request.args.get('max'))
except (TypeError, ValueError):
raise HTTPError(http.BAD_REQUEST)
if max_results:
recently_added = auth.user.recently_added[:max_results]
else:
recently_added = auth.user.recently_added

contribs = [
utils.add_contributor_json(contrib, get_current_user())
for contrib in auth.user.recently_added
for contrib in recently_added
if contrib.is_active()
if contrib._id not in node.contributors
]
Expand Down

0 comments on commit 6d5d909

Please sign in to comment.