allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [4/9] allura git commit: [#8051] ticket:895 export_attachments refactoring, fix Ticket.__json__
Date Tue, 08 Mar 2016 21:35:13 GMT
[#8051] ticket:895 export_attachments refactoring, fix Ticket.__json__


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

Branch: refs/heads/master
Commit: f048690203cc062695da6fbd319946e6619f96e6
Parents: 1097cfa
Author: Denis Kotov <deniskkotov@gmail.com>
Authored: Sat Jan 30 01:08:30 2016 +0200
Committer: Heith Seewald <heiths@gmail.com>
Committed: Tue Mar 8 14:11:57 2016 -0500

----------------------------------------------------------------------
 Allura/allura/app.py                          | 14 ++++++++++++++
 ForgeBlog/forgeblog/main.py                   | 18 ++++--------------
 ForgeDiscussion/forgediscussion/forum_main.py | 19 +++++--------------
 ForgeTracker/forgetracker/model/ticket.py     |  2 +-
 ForgeTracker/forgetracker/tracker_main.py     | 17 ++---------------
 ForgeWiki/forgewiki/wiki_main.py              | 17 ++---------------
 6 files changed, 28 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 6098337..0844c94 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -761,6 +761,20 @@ class Application(object):
     def get_attachment_export_path(self, path='', *args):
         return os.path.join(path, self.config.options.mount_point, *args)
 
+    def make_dir_for_attachments(self, path):
+        if not os.path.exists(path):
+                os.makedirs(path)
+
+    def save_attachments(self, path, attachments):
+        self.make_dir_for_attachments(path)
+        for attachment in attachments:
+            attachment_path = os.path.join(
+                path,
+                attachment.filename
+            )
+            with open(attachment_path, 'w') as fl:
+                fl.write(attachment.rfile().read())
+
 
 class AdminControllerMixin(object):
     """Provides common functionality admin controllers need"""

http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index c733584..96d809c 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -223,24 +223,14 @@ class ForgeBlogApp(Application):
 
     def export_attachments(self, articles, export_path):
         for article in articles:
-            attachment_path = self.get_attachment_export_path(export_path, str(article._id))
-            if not os.path.exists(attachment_path):
-                os.makedirs(attachment_path)
             for post in article.discussion_thread.query_posts(status='ok'):
-                post_path = os.path.join(
-                    attachment_path,
+                post_path = self.get_attachment_export_path(
+                    export_path,
+                    str(article._id),
                     article.discussion_thread._id,
                     post.slug
                 )
-                if not os.path.exists(post_path):
-                    os.makedirs(post_path)
-                for attachment in post.attachments:
-                    path = os.path.join(
-                        post_path,
-                        attachment.filename
-                    )
-                    with open(path, 'w') as fl:
-                        fl.write(attachment.rfile().read())
+                self.save_attachments(post_path, post.attachments)
 
 
 class RootController(BaseController, FeedController):

http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/ForgeDiscussion/forgediscussion/forum_main.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/forum_main.py b/ForgeDiscussion/forgediscussion/forum_main.py
index 3502191..524b11d 100644
--- a/ForgeDiscussion/forgediscussion/forum_main.py
+++ b/ForgeDiscussion/forgediscussion/forum_main.py
@@ -254,23 +254,14 @@ class ForgeDiscussionApp(Application):
 
     def export_attachments(self, threads, export_path):
         for thread in threads:
-            attachment_path = self.get_attachment_export_path(export_path, str(thread.artifact._id),
thread._id)
-            if not os.path.exists(attachment_path):
-                os.makedirs(attachment_path)
             for post in thread.query_posts(status='ok'):
-                post_path = os.path.join(
-                    attachment_path,
+                post_path = self.get_attachment_export_path(
+                    export_path,
+                    str(thread.artifact._id),
+                    thread._id,
                     post.slug
                 )
-                if not os.path.exists(post_path):
-                    os.makedirs(post_path)
-                for attachment in post.attachments:
-                    path = os.path.join(
-                        post_path,
-                        attachment.filename
-                    )
-                    with open(path, 'w') as fl:
-                        fl.write(attachment.rfile().read())
+                self.save_attachments(post_path, post.attachments)
 
 
 class ForumAdminController(DefaultAdminController):

http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 902be5b..dde75ca 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1126,7 +1126,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 if parent == VersionedArtifact:
                     kwargs['posts_limit'] = posts_limit
                 try:
-                    parents_json.update(parent.__json__(self, is_export=True, **kwargs))
+                    parents_json.update(parent.__json__(self, is_export=is_export, **kwargs))
                 except:
                     parents_json.update(parent.__json__(self, **kwargs))
 

http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index a046243..7e9036f 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -517,12 +517,7 @@ class ForgeTrackerApp(Application):
     def export_attachments(self, tickets, export_path):
         for ticket in tickets:
             attachment_path = self.get_attachment_export_path(export_path, str(ticket._id))
-            if not os.path.exists(attachment_path):
-                os.makedirs(attachment_path)
-            for attachment in ticket.attachments:
-                path = os.path.join(attachment_path, attachment.filename)
-                with open(path, 'w') as fl:
-                    fl.write(attachment.rfile().read())
+            self.save_attachments(attachment_path, ticket.attachments)
 
             for post in ticket.discussion_thread.query_posts(status='ok'):
                 post_path = os.path.join(
@@ -530,15 +525,7 @@ class ForgeTrackerApp(Application):
                     ticket.discussion_thread._id,
                     post.slug
                 )
-                if not os.path.exists(post_path):
-                    os.makedirs(post_path)
-                for attachment in post.attachments:
-                    path = os.path.join(
-                        post_path,
-                        attachment.filename
-                    )
-                    with open(path, 'w') as fl:
-                        fl.write(attachment.rfile().read())
+                self.save_attachments(post_path, post.attachments)
 
     @property
     def bins(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/f0486902/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index e865d5c..1621f62 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -358,12 +358,7 @@ The wiki uses [Markdown](%s) syntax.
     def export_attachments(self, pages, export_path):
         for page in pages:
             attachment_path = self.get_attachment_export_path(export_path, str(page._id))
-            if not os.path.exists(attachment_path):
-                os.makedirs(attachment_path)
-            for attachment in page.attachments:
-                path = os.path.join(attachment_path, attachment.filename)
-                with open(path, 'w') as fl:
-                    fl.write(attachment.rfile().read())
+            self.save_attachments(attachment_path, page.attachments)
 
             for post in page.discussion_thread.query_posts(status='ok'):
                 post_path = os.path.join(
@@ -371,15 +366,7 @@ The wiki uses [Markdown](%s) syntax.
                     page.discussion_thread._id,
                     post.slug
                 )
-                if not os.path.exists(post_path):
-                    os.makedirs(post_path)
-                for attachment in post.attachments:
-                    path = os.path.join(
-                        post_path,
-                        attachment.filename
-                    )
-                    with open(path, 'w') as fl:
-                        fl.write(attachment.rfile().read())
+                self.save_attachments(post_path, post.attachments)
 
 
 class RootController(BaseController, DispatchIndex, FeedController):


Mime
View raw message