incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [19/50] git commit: [#3154] ticket:390 Bulk export: discussion
Date Wed, 21 Aug 2013 20:12:35 GMT
[#3154]  ticket:390 Bulk export: discussion


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

Branch: refs/heads/db/3154b
Commit: 33a79645d8e31ac8e9f8f11138dfcdf64caee97c
Parents: 9f6cc39
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Fri Jul 26 10:31:30 2013 +0400
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Aug 21 18:12:25 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/discuss.py                  |  9 ++--
 ForgeDiscussion/forgediscussion/forum_main.py   | 14 +++++-
 ForgeDiscussion/forgediscussion/model/forum.py  |  6 ---
 .../forgediscussion/tests/test_app.py           | 50 ++++++++++++++++++++
 4 files changed, 69 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/33a79645/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index d13b7e9..ec5ccdc 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -64,8 +64,9 @@ class Discussion(Artifact, ActivityObject):
             shortname=self.shortname,
             name=self.name,
             description=self.description,
-            threads=[dict(_id=t._id, subject=t.subject)
-                     for t in self.threads])
+            threads=[t.__json__() for t in self.thread_class().query.find(
+                dict(discussion_id=self._id)).sort(
+                    'last_post_date', pymongo.DESCENDING)])
 
     @property
     def activity_name(self):
@@ -169,7 +170,9 @@ class Thread(Artifact, ActivityObject):
                         subject=p.subject,
                         attachments=[dict(bytes=attach.length,
                                           url=h.absurl(attach.url())) for attach in p.attachments])
-                   for p in self.posts if p.status == 'ok'])
+                   for p in self.post_class().query.find(
+                   dict(discussion_id=self.discussion_id, thread_id=self._id, status='ok')
+                   ).sort('timestamp', pymongo.DESCENDING)])
 
     @property
     def activity_name(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/33a79645/ForgeDiscussion/forgediscussion/forum_main.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/forum_main.py b/ForgeDiscussion/forgediscussion/forum_main.py
index 730f007..2465312 100644
--- a/ForgeDiscussion/forgediscussion/forum_main.py
+++ b/ForgeDiscussion/forgediscussion/forum_main.py
@@ -19,12 +19,13 @@
 import logging
 import urllib
 from itertools import islice
+import json
 
 # Non-stdlib imports
 import pymongo
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
-from tg import expose, redirect, flash, url, validate
+from tg import expose, redirect, flash, url, validate, jsonify
 from tg.decorators import with_trailing_slash
 from bson import ObjectId
 from ming import schema
@@ -67,6 +68,7 @@ class ForgeDiscussionApp(Application):
     PostClass=DM.ForumPost
     AttachmentClass=DM.ForumAttachment
     searchable=True
+    exportable=True
     tool_label='Discussion'
     tool_description="""
         Collaborate with your community in your forum.
@@ -215,6 +217,16 @@ class ForgeDiscussionApp(Application):
         DM.ForumPost.query.remove(dict(app_config_id=self.config._id))
         super(ForgeDiscussionApp, self).uninstall(project)
 
+    def bulk_export(self, f):
+        f.write('{"forums": [')
+        forums = DM.Forum.query.find(dict(app_config_id=self.config._id)).sort('mod_date',
pymongo.DESCENDING).all()
+        count = len(forums)
+        for i, forum in enumerate(forums):
+            json.dump(forum, f, cls=jsonify.GenericJSON)
+            if i < (count - 1):
+                f.write(',')
+        f.write(']}')
+
 class ForumAdminController(DefaultAdminController):
 
     def _check_security(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/33a79645/ForgeDiscussion/forgediscussion/model/forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/model/forum.py b/ForgeDiscussion/forgediscussion/model/forum.py
index 42d1dc0..84040da 100644
--- a/ForgeDiscussion/forgediscussion/model/forum.py
+++ b/ForgeDiscussion/forgediscussion/model/forum.py
@@ -194,12 +194,6 @@ 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/33a79645/ForgeDiscussion/forgediscussion/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/test_app.py b/ForgeDiscussion/forgediscussion/tests/test_app.py
new file mode 100644
index 0000000..d54ab5a
--- /dev/null
+++ b/ForgeDiscussion/forgediscussion/tests/test_app.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+#-*- python -*-
+
+import tempfile
+import json
+from nose.tools import assert_equal
+
+from allura import model as M
+from forgediscussion.tests.functional.test_rest import TestDiscussionApiBase
+
+
+class TestBulkExport(TestDiscussionApiBase):
+
+    def test_bulk_export(self):
+        project = M.Project.query.get(shortname='test')
+        discussion = project.app_instance('discussion')
+        f = tempfile.TemporaryFile()
+        discussion.bulk_export(f)
+        f.seek(0)
+        discussion = json.loads(f.read())
+        forums = discussion['forums']
+
+        assert_equal(forums[0]['shortname'], u'general')
+        assert_equal(forums[0]['description'], u'Forum about anything you want to talk about.')
+        assert_equal(forums[0]['name'], u'General Discussion')
+        assert_equal(forums[0]['threads'][0]['posts'][0]['text'], u'Hi boys and girls')
+        assert_equal(forums[0]['threads'][0]['posts'][0]['subject'], u'Hi guys')
+        assert_equal(forums[0]['threads'][1]['posts'][0]['text'], u'1st post')
+        assert_equal(forums[0]['threads'][1]['posts'][0]['subject'], u"Let's talk")
+        assert_equal(forums[1]['shortname'], u'héllo')
+        assert_equal(forums[1]['description'], u'Say héllo here')
+        assert_equal(forums[1]['name'], u'Say Héllo')


Mime
View raw message