You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/08/23 18:58:42 UTC
[42/50] git commit: [#3154] revise commit 099b2c so project metadata
is on AdminApp and less special handling is needed
[#3154] revise commit 099b2c so project metadata is on AdminApp and less special handling is needed
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/587f2d35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/587f2d35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/587f2d35
Branch: refs/heads/cj/6530
Commit: 587f2d358d15ca64b826b24e016220afbfa8e9e6
Parents: e564195
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Aug 16 21:20:26 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 22 20:04:46 2013 +0000
----------------------------------------------------------------------
Allura/allura/ext/admin/admin_main.py | 25 +++++++++++-----------
Allura/allura/ext/admin/templates/export.html | 5 -----
Allura/allura/model/project.py | 6 +-----
Allura/allura/tasks/export_tasks.py | 24 +++++++++------------
Allura/allura/tests/functional/test_admin.py | 13 ++++-------
5 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/587f2d35/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 f763258..cbb1e2c 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -19,12 +19,13 @@ import logging
from collections import defaultdict
from datetime import datetime
from urlparse import urlparse
+import json
import pkg_resources
from pylons import tmpl_context as c, app_globals as g
from pylons import request
from paste.deploy.converters import asbool
-from tg import expose, redirect, flash, validate, config
+from tg import expose, redirect, flash, validate, config, jsonify
from tg.decorators import with_trailing_slash, without_trailing_slash
from webob import exc
from bson import ObjectId
@@ -74,13 +75,13 @@ class AdminApp(Application):
__version__ = version.__version__
installable=False
_installable_tools = None
- _exportable_tools = None
tool_label = 'admin'
icons={
24:'images/admin_24.png',
32:'images/admin_32.png',
48:'images/admin_48.png'
}
+ exportable = True
def __init__(self, project, config):
Application.__init__(self, project, config)
@@ -105,15 +106,11 @@ class AdminApp(Application):
@staticmethod
def exportable_tools_for(project):
- cls = AdminApp
- tools = [project]
- if cls._exportable_tools is None:
- for tool in project.ordered_mounts(include_hidden=True):
- if not tool.get('ac'):
- continue
- if project.app_instance(tool['ac']).exportable:
- tools.append(tool['ac'])
- return tools
+ tools = []
+ for tool in project.app_configs:
+ if project.app_instance(tool).exportable:
+ tools.append(tool)
+ return sorted(tools, key=lambda t: t.options.mount_point)
def main_menu(self):
'''Apps should provide their entries to be added to the main nav
@@ -168,6 +165,9 @@ class AdminApp(Application):
def install(self, project):
pass
+ def bulk_export(self, f):
+ json.dump(self.project, f, cls=jsonify.GenericJSON, indent=2)
+
class AdminExtensionLookup(object):
@@ -645,8 +645,7 @@ class ProjectAdminController(BaseController):
redirect('export')
if isinstance(tools, basestring):
tools = [tools]
- allowed = set(t.options.mount_point for t in exportable_tools if hasattr(t, 'options'))
- allowed.add('project')
+ allowed = set(t.options.mount_point for t in exportable_tools)
if not set(tools).issubset(allowed):
flash('Wrong tools in input data', 'error')
redirect('export')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/587f2d35/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 6287be7..eff9d5a 100644
--- a/Allura/allura/ext/admin/templates/export.html
+++ b/Allura/allura/ext/admin/templates/export.html
@@ -38,13 +38,8 @@
<form method="POST" action="">
{% for tool in tools %}
<div class="grid-19">
- {% if tool.name %}
- <input type="checkbox" name="tools" id="tool-{{ loop.index }}" value="project">
- <label for="tool-{{ loop.index }}">{{ tool.name }}</label> <a href="{{ tool.url() }}">{{ tool.url() }}</a>
- {% else %}
<input type="checkbox" name="tools" id="tool-{{ loop.index }}" value="{{ tool.options.mount_point }}">
<label for="tool-{{ loop.index }}">{{ tool.options.mount_label }}</label> <a href="{{ tool.url() }}">{{ tool.url() }}</a>
- {% endif %}
</div>
{% endfor %}
<p><div class="grid-19"><input type="submit" value="Export"></div></p>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/587f2d35/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 021bb47..95ad80f 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -17,13 +17,12 @@
import os
import logging
-import json
from collections import Counter, OrderedDict
from datetime import datetime
from copy import deepcopy
import urllib
-from tg import config, jsonify
+from tg import config
from pylons import tmpl_context as c, app_globals as g
from pylons import request
from paste.deploy.converters import asbool
@@ -877,9 +876,6 @@ class Project(MappedClass, ActivityNode, ActivityObject):
elif os.path.exists(tmpdir):
return 'busy'
- def bulk_export(self, f):
- json.dump(self, f, cls=jsonify.GenericJSON, indent=2)
-
def __json__(self):
return dict(
shortname=self.shortname,
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/587f2d35/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 4b30c36..b6a84ac 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -46,26 +46,22 @@ def bulk_export(project_shortname, tools, username, neighborhood):
return
not_exported_tools = []
for tool in tools or []:
- entry_to_export = None
- if tool == 'project':
- entry_to_export = project
- else:
- entry_to_export = project.app_instance(tool)
- if not entry_to_export:
- log.info('Can not load app for %s mount point. Skipping.' % tool)
- not_exported_tools.append(tool)
- continue
- if not entry_to_export.exportable:
- log.info('Tool %s is not exportable. Skipping.' % tool)
- not_exported_tools.append(tool)
- continue
+ app = project.app_instance(tool)
+ if not app:
+ log.info('Can not load app for %s mount point. Skipping.' % tool)
+ not_exported_tools.append(tool)
+ continue
+ if not app.exportable:
+ log.info('Tool %s is not exportable. Skipping.' % tool)
+ not_exported_tools.append(tool)
+ continue
log.info('Exporting %s...' % tool)
try:
path = create_export_dir(project)
temp_name = mkstemp(dir=path)[1]
with open(temp_name, 'w') as f:
with h.push_context(project._id):
- entry_to_export.bulk_export(f)
+ app.bulk_export(f)
os.rename(temp_name, os.path.join(path, '%s.json' % tool))
except:
log.error('Something went wrong during export of %s' % tool, exc_info=True)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/587f2d35/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 4988a8c..669f113 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -784,11 +784,8 @@ class TestExport(TestController):
def test_exportable_tools_for(self):
project = M.Project.query.get(shortname='test')
exportable_tools = AdminApp.exportable_tools_for(project)
- tools = [t.options.mount_point
- for t in AdminApp.exportable_tools_for(project)
- if hasattr(t, 'options')]
- assert_equals(tools, [u'wiki', u'wiki2'])
- assert_in(project, exportable_tools)
+ exportable_mount_points = [t.options.mount_point for t in exportable_tools]
+ assert_equals(exportable_mount_points, [u'admin', u'wiki', u'wiki2'])
def test_access(self):
r = self.app.get('/admin/export',
@@ -824,10 +821,8 @@ class TestExport(TestController):
with mock.patch('allura.ext.search.search_main.SearchApp.exportable'):
project = M.Project.query.get(shortname='test')
exportable_tools = AdminApp.exportable_tools_for(project)
- tools = [t.options.mount_point for t in exportable_tools
- if hasattr(t, 'options')]
- assert_equals(tools, [u'search', u'wiki', u'wiki2'])
- assert_in(project, exportable_tools)
+ exportable_mount_points = [t.options.mount_point for t in exportable_tools]
+ assert_equals(exportable_mount_points, [u'admin', u'search', u'wiki', u'wiki2'])
def test_tools_not_selected(self):
r = self.app.post('/admin/export')