incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [04/11] git commit: [#5650] ticket:323 Pagination for forum list
Date Wed, 26 Jun 2013 22:56:59 GMT
[#5650] ticket:323 Pagination for forum list


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ed29d9db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ed29d9db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ed29d9db

Branch: refs/heads/master
Commit: ed29d9dbc0fa5569526a3a4373808c4290304d48
Parents: 1a3f846
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri May 3 13:25:11 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Jun 26 22:56:12 2013 +0000

----------------------------------------------------------------------
 ForgeDiscussion/forgediscussion/controllers/root.py | 13 ++++++++++---
 .../forgediscussion/tests/functional/test_rest.py   | 16 ++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ed29d9db/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index cc21070..bef02b1 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -222,11 +222,14 @@ class RootRestController(BaseController):
         return ForumRestController(unquote(forum)), remainder
 
     @expose('json:')
-    def index(self, **kw):
+    def index(self, limit=100, page=0, **kw):
+        limit, page, start = g.handle_paging(int(limit), int(page))
         forums = model.Forum.query.find(dict(
                         app_config_id=c.app.config._id,
-                        parent_id=None, deleted=False)).all()
-        return dict(forums=[dict(_id=f._id,
+                        parent_id=None, deleted=False)
+                ).skip(start).limit(limit)
+        count = forums.count()
+        json = dict(forums=[dict(_id=f._id,
                                  name=f.name,
                                  shortname=f.shortname,
                                  description=f.description,
@@ -234,6 +237,10 @@ class RootRestController(BaseController):
                                  last_post=f.last_post,
                                  url=h.absurl('/rest' + f.url()))
                             for f in forums])
+        json['limit'] = limit
+        json['page'] = page
+        json['count'] = count
+        return json
 
     @expose('json:')
     def validate_import(self, doc=None, username_mapping=None, **kw):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ed29d9db/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py b/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
index f1de12e..d335d6b 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
@@ -97,3 +97,19 @@ class TestRootRestController(TestDiscussionApiBase):
         assert_equal(topic['subject'], 'Hi guys')
         assert_equal(topic['posts'][0]['text'], 'Hi boys and girls')
         assert_equal(topic['posts'][0]['subject'], 'Hi guys')
+
+    def test_forum_list_pagination(self):
+        resp = self.app.get('/rest/p/test/discussion/?limit=1')
+        forums = resp.json['forums']
+        assert_equal(len(forums), 1)
+        assert_equal(forums[0]['name'], 'General Discussion')
+        assert_equal(resp.json['count'], 2)
+        assert_equal(resp.json['page'], 0)
+        assert_equal(resp.json['limit'], 1)
+        resp = self.app.get('/rest/p/test/discussion/?limit=1&page=1')
+        forums = resp.json['forums']
+        assert_equal(len(forums), 1)
+        assert_equal(forums[0]['name'], u'Say Héllo')
+        assert_equal(resp.json['count'], 2)
+        assert_equal(resp.json['page'], 1)
+        assert_equal(resp.json['limit'], 1)


Mime
View raw message