allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [1/9] allura git commit: [#6662] ticket:896 Add queries to getting size of attachments
Date Tue, 08 Mar 2016 21:35:10 GMT
Repository: allura
Updated Branches:
  refs/heads/master 672ac23b0 -> 80e402e53


[#6662] ticket:896 Add queries to getting size of attachments


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

Branch: refs/heads/master
Commit: ee53408c61fb1ee60c924a3568ec09e6dd385e20
Parents: 2dd2ff0
Author: Denis Kotov <deniskkotov@gmail.com>
Authored: Mon Feb 1 22:54:48 2016 +0200
Committer: Denis Kotov <deniskkotov@gmail.com>
Committed: Mon Feb 1 22:54:48 2016 +0200

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py         | 31 +++++++++++++++++-----
 Allura/allura/ext/admin/templates/export.html |  4 +++
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ee53408c/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 45d5cc8..f33f5b7 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -44,6 +44,7 @@ from allura.controllers import BaseController
 from allura.lib.decorators import require_post
 from allura.tasks import export_tasks
 from allura.lib.widgets.project_list import ProjectScreenshots
+from allura.lib.utils import is_ajax
 
 from . import widgets as aw
 
@@ -176,7 +177,7 @@ class AdminApp(Application):
     def install(self, project):
         pass
 
-    def bulk_export(self, f):
+    def bulk_export(self, f, export_path='', with_attachments=False):
         json.dump(self.project, f, cls=jsonify.GenericJSON, indent=2)
 
 
@@ -762,12 +763,12 @@ class ProjectAdminController(BaseController):
         redirect(request.referer)
 
     @expose('jinja:allura.ext.admin:templates/export.html')
-    def export(self, tools=None):
+    def export(self, tools=None, with_attachments=False):
         if not asbool(config.get('bulk_export_enabled', True)):
             raise exc.HTTPNotFound()
         if request.method == 'POST':
             try:
-                ProjectAdminRestController().export(tools, send_email=True)
+                ProjectAdminRestController().export(tools, send_email=True, with_attachments=with_attachments)
             except (exc.HTTPBadRequest, exc.HTTPServiceUnavailable) as e:
                 flash(str(e), 'error')
                 redirect('.')
@@ -777,9 +778,27 @@ class ProjectAdminController(BaseController):
                 redirect('export')
 
         exportable_tools = AdminApp.exportable_tools_for(c.project)
+        apps_id = [tool._id for tool in exportable_tools]
+        db = M.session.project_doc_session.db
+        files_id = db.attachment.find({"app_config_id": {"$in": apps_id}}).distinct("file_id")
+        try:
+            total_size = db.attachment.files.aggregate([
+                {
+                    "$match": {"_id": {"$in": files_id}}
+                },
+                {
+                    "$group": {"_id": "total", "total_size": {"$sum": "$length"}}
+                },
+                {
+                    "$project": {"_id": 0, "total_size": {"$divide": ["$total_size", 1000000]}}
+                }
+            ]).get('result')[0].get('total_size')
+        except IndexError:
+            total_size = 0
         return {
             'tools': exportable_tools,
-            'status': c.project.bulk_export_status()
+            'status': c.project.bulk_export_status(),
+            'total_size': round(total_size, 3)
         }
 
 
@@ -863,7 +882,7 @@ class ProjectAdminRestController(BaseController):
 
     @expose('json:')
     @require_post()
-    def export(self, tools=None, send_email=False, **kw):
+    def export(self, tools=None, send_email=False, with_attachments=False, **kw):
         """
         Initiate a bulk export of the project data.
 
@@ -899,7 +918,7 @@ class ProjectAdminRestController(BaseController):
         # filename (potentially) includes a timestamp, so we have
         # to pre-generate to be able to return it to the user
         filename = c.project.bulk_export_filename()
-        export_tasks.bulk_export.post(tools, filename, send_email=send_email)
+        export_tasks.bulk_export.post(tools, filename, send_email=send_email, with_attachments=with_attachments)
         return {
             'status': 'in progress',
             'filename': filename,

http://git-wip-us.apache.org/repos/asf/allura/blob/ee53408c/Allura/allura/ext/admin/templates/export.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/export.html b/Allura/allura/ext/admin/templates/export.html
index c8b7c2b..fed834f 100644
--- a/Allura/allura/ext/admin/templates/export.html
+++ b/Allura/allura/ext/admin/templates/export.html
@@ -55,6 +55,10 @@
         <label for="tool-{{ loop.index }}">{{ tool.options.mount_label }}</label>
<a href="{{ tool.url() }}">{{ tool.url() }}</a>
       </div>
       {% endfor %}
+      <p>&nbsp;</p>
+      <div class="grid-19">
+        <input type="checkbox" id="with_attachments" name="with_attachments"><label
for="with_attachments">With attachments (attachments size: {{ total_size }} MB)</label><br>
+      </div>
       <p><div class="grid-19"><input type="submit" value="Export" {% if status
== 'busy' %}disabled{% endif %}></div></p>
       {{lib.csrf_token()}}
     </form>


Mime
View raw message