incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [11/11] git commit: [#5650] ticket:323 Pagination for topic's posts
Date Wed, 26 Jun 2013 22:57:06 GMT
[#5650] ticket:323 Pagination for topic's posts


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

Branch: refs/heads/master
Commit: 44ad385c3eb62b2ec6723e16d06d47eaed691a92
Parents: f1b854c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue May 7 09:50:04 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Jun 26 22:56:12 2013 +0000

----------------------------------------------------------------------
 .../forgediscussion/controllers/root.py          | 14 ++++++++++++--
 ForgeDiscussion/forgediscussion/model/forum.py   |  6 ++++++
 .../tests/functional/test_rest.py                | 19 +++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44ad385c/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 7ff7fcb..1f577f2 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -332,5 +332,15 @@ class ForumTopicRestController(BaseController):
         require_access(self.forum, 'read')
 
     @expose('json:')
-    def index(self, **kw):
-        return dict(topic=self.topic)
+    def index(self, limit=100, page=0, **kw):
+        limit, page, start = g.handle_paging(int(limit), int(page))
+        posts = model.ForumPost.query.find(dict(thread_id=self.topic._id))
+        posts = posts.skip(start).limit(limit)
+        count = posts.count()
+        json = {}
+        json['topic'] = self.topic.__json__()
+        json['topic']['posts'] = posts.all()
+        json['count'] = count
+        json['page'] = page
+        json['limit'] = limit
+        return json

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44ad385c/ForgeDiscussion/forgediscussion/model/forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/model/forum.py b/ForgeDiscussion/forgediscussion/model/forum.py
index e8f920a..1a4a734 100644
--- a/ForgeDiscussion/forgediscussion/model/forum.py
+++ b/ForgeDiscussion/forgediscussion/model/forum.py
@@ -200,6 +200,12 @@ class ForumThread(M.Thread):
             {'$set':dict(discussion_id=new_forum._id)})
         self.discussion_id = new_forum._id
 
+    def __json__(self):
+        return dict(
+            _id=self._id,
+            discussion_id=str(self.discussion_id),
+            subject=self.subject)
+
 
 class ForumPostHistory(M.PostHistory):
     class __mongometa__:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44ad385c/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 87c2fda..45ef742 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_rest.py
@@ -131,6 +131,25 @@ class TestRootRestController(TestDiscussionApiBase):
         assert_equal(resp.json['page'], 1)
         assert_equal(resp.json['limit'], 1)
 
+    def test_topic_pagination(self):
+        thread = ForumThread.query.find({'subject': 'Hi guys'}).first()
+        thread.post('Hi guy', 'I am second post')
+        url = '/rest/p/test/discussion/general/thread/%s/' % thread._id
+        resp = self.app.get(url + '?limit=1')
+        posts = resp.json['topic']['posts']
+        assert_equal(len(posts), 1)
+        assert_equal(posts[0]['text'], 'Hi boys and girls')
+        assert_equal(resp.json['count'], 2)
+        assert_equal(resp.json['page'], 0)
+        assert_equal(resp.json['limit'], 1)
+        resp = self.app.get(url + '?limit=1&page=1')
+        posts = resp.json['topic']['posts']
+        assert_equal(len(posts), 1)
+        assert_equal(posts[0]['text'], 'I am second post')
+        assert_equal(resp.json['count'], 2)
+        assert_equal(resp.json['page'], 1)
+        assert_equal(resp.json['limit'], 1)
+
     def test_security(self):
         p = M.Project.query.get(shortname='test')
         acl = p.app_instance('discussion').config.acl


Mime
View raw message