[#4943] ticket:259 * added the error message to the log
* rename default_tools to anchored_tools
* removed get_default_tools_order
* changed from dict to OrderedDict in get_anchored_tools
* set is_missing = ''
* fixed test
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b58e89d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b58e89d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b58e89d9
Branch: refs/heads/cj/5705
Commit: b58e89d9fedd458fb4baf1c3dbb00489642da392
Parents: 60eb5df
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Jan 21 05:02:07 2013 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Thu Jan 31 20:26:30 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/project.py | 14 +++---
.../allura/ext/admin/templates/project_tools.html | 8 ++-
Allura/allura/lib/widgets/forms.py | 2 +-
Allura/allura/model/neighborhood.py | 15 ++-----
Allura/allura/model/project.py | 31 +++++++--------
.../widgets/neighborhood_overview_form.html | 4 +-
.../allura/tests/functional/test_neighborhood.py | 18 ++++----
Allura/allura/tests/model/test_neighborhood.py | 7 +--
Allura/allura/tests/model/test_project.py | 5 +-
9 files changed, 49 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 0932b2b..5aa9e02 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -521,24 +521,24 @@ class NeighborhoodAdminController(object):
tracking_id = kw.get('tracking_id', '')
h.log_if_changed(nbhd, 'tracking_id', tracking_id,
'update neighborhood tracking_id')
- default_tools = kw.get('default_tools', '')
+ anchored_tools = kw.get('anchored_tools', '')
validate_tools = dict()
result = True
- if default_tools.strip() != '':
+ if anchored_tools.strip() != '':
try:
- validate_tools = dict((tool.split(':')[0].lower(), tool.split(':')[1]) for
tool in default_tools.replace(' ', '').split(','))
+ validate_tools = dict((tool.split(':')[0].lower(), tool.split(':')[1]) for
tool in anchored_tools.replace(' ', '').split(','))
except Exception:
- flash('Default tools "%s" is invalid' % default_tools,'error')
+ flash('Anchored tools "%s" is invalid' % anchored_tools,'error')
result = False
for tool in validate_tools.keys():
if not h.re_path_portion.match(tool):
- flash('Default tools "%s" is invalid' % default_tools,'error')
+ flash('Anchored tools "%s" is invalid' % anchored_tools,'error')
result = False
if result:
- h.log_if_changed(nbhd, 'default_tools', default_tools,
- 'update neighborhood default tools')
+ h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
+ 'update neighborhood anchored tools')
if icon is not None and icon != '':
if self.neighborhood.icon:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/ext/admin/templates/project_tools.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_tools.html b/Allura/allura/ext/admin/templates/project_tools.html
index 857dfee..1029e31 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -52,7 +52,7 @@
{% set links = app.admin_menu() %}
{% set label = mount['ac'].options['mount_label'] if mount['ac'].options['mount_label']
!= 'Tool Name' else mount['ac'].options['mount_point'] %}
- <div class="fleft {%if app.tool_label.lower() in app.project.neighborhood.get_default_tools().keys()%}isnt_sorted{%endif%}">
+ <div class="fleft {%if app.tool_label.lower() in app.project.neighborhood.get_anchored_tools().keys()%}isnt_sorted{%endif%}">
<ul class="deck">
<li class="tcenter">
<span class="tool_title">{{ label }}</span><br />
@@ -63,7 +63,7 @@
<a href="{{ link.url }}" class="{{ link.className }}">{{ link.label
}}</a>
</li>
{% endfor %}
- {% if app.uninstallable and not (app.tool_label.lower() in app.project.neighborhood.get_default_tools().keys())
%}
+ {% if app.uninstallable and not (app.tool_label.lower() in app.project.neighborhood.get_anchored_tools().keys())
%}
<li>
<form method="post" action="update_mounts" id="mounts_edit_2-{{loop.index0}}">
<input type="hidden" class="mount_point"
@@ -141,7 +141,9 @@
.pad .fourcol .fleft {
min-height: 200px;
}
-
+div.isnt_sorted > ul.deck {
+ cursor: not-allowed;
+}
#configure_grouping_form {
padding-left: 10px;
}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 797fdc0..037f136 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -641,7 +641,7 @@ class NeighborhoodOverviewForm(ForgeForm):
icon = ew.FileField()
tracking_id = ew.TextField()
project_list_url = ew.TextField(validator=fev.URL())
- default_tools = ffw.AutoResizeTextarea()
+ anchored_tools = ffw.AutoResizeTextarea()
def from_python(self, value, state):
if value.features['css'] == "picker":
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/model/neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/neighborhood.py b/Allura/allura/model/neighborhood.py
index b9303ff..d22064a 100644
--- a/Allura/allura/model/neighborhood.py
+++ b/Allura/allura/model/neighborhood.py
@@ -1,6 +1,7 @@
import re
import json
import logging
+from collections import OrderedDict
from ming import schema as S
from ming.orm import FieldProperty, RelationProperty, ForeignIdProperty
@@ -66,7 +67,7 @@ class Neighborhood(MappedClass):
max_projects=S.Int,
css=str,
google_analytics=bool))
- default_tools = FieldProperty(str, if_missing='summary:Summary, files:Files, reviews:Reviews,
support:Support')
+ anchored_tools = FieldProperty(str, if_missing='')
def parent_security_context(self):
return None
@@ -238,15 +239,9 @@ class Neighborhood(MappedClass):
def migrate_css_for_picker(self):
self.css = ""
- def get_default_tools(self):
- default_tools = self.default_tools.replace(' ', '').split(',')
+ def get_anchored_tools(self):
+ anchored_tools = self.anchored_tools.replace(' ', '').split(',')
try:
- return dict((tool.split(':')[0].lower(), tool.split(':')[1]) for tool in default_tools)
+ return OrderedDict((tool.split(':')[0].lower(), tool.split(':')[1]) for tool
in anchored_tools)
except Exception:
return dict()
-
- def get_default_tools_order(self):
- if not len(self.default_tools.strip()):
- return []
- default_tools = self.default_tools.replace(' ', '').split(',')
- return [tool.split(':')[0].lower() for tool in default_tools]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index da5e363..be121df 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -391,9 +391,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
from allura.app import SitemapEntry
entries = []
- default_tools_order =self.neighborhood.get_default_tools_order()
- i = len(default_tools_order)
- self.install_default_tools()
+ anchored_tools =self.neighborhood.get_anchored_tools()
+ i = len(anchored_tools)
+ self.install_anchored_tools()
# Set menu mode
delta_ordinal = i
@@ -425,8 +425,8 @@ class Project(MappedClass, ActivityNode, ActivityObject):
entry = sm.bind_app(app)
entry.tool_name = ac.tool_name
entry.ui_icon = 'tool-%s' % entry.tool_name.lower()
- if not self.is_nbhd_project and (entry.tool_name.lower() in default_tools_order):
- ordinal = default_tools_order.index(entry.tool_name.lower())
+ if not self.is_nbhd_project and (entry.tool_name.lower() in anchored_tools.keys()):
+ ordinal = anchored_tools.keys().index(entry.tool_name.lower())
else:
ordinal = int(ac.options.get('ordinal', 0)) + delta_ordinal
if ordinal > max_ordinal:
@@ -440,18 +440,17 @@ class Project(MappedClass, ActivityNode, ActivityObject):
entries = sorted(entries, key=lambda e: e['ordinal'])
return [e['entry'] for e in entries]
- def install_default_tools(self):
- default_tools = self.neighborhood.get_default_tools()
- default_tools_order =self.neighborhood.get_default_tools_order()
+ def install_anchored_tools(self):
+ anchored_tools = self.neighborhood.get_anchored_tools()
installed_tools = [tool.tool_name.lower() for tool in self.app_configs]
i = 0
if not self.is_nbhd_project:
- for tool in default_tools_order:
+ for tool in anchored_tools.keys():
if tool not in installed_tools:
try:
- self.install_app(tool, tool, default_tools[tool], i)
+ self.install_app(tool, tool, anchored_tools[tool], i)
except Exception:
- log.error(tool + ' is not available')
+ log.error('%s is not available' % tool, exc_info=True)
i += 1
def grouped_navbar_entries(self):
@@ -599,17 +598,17 @@ class Project(MappedClass, ActivityNode, ActivityObject):
'''Returns an array of a projects mounts (tools and sub-projects) in
toolbar order.'''
result = []
- default_tools_order = self.neighborhood.get_default_tools_order()
- i = len(default_tools_order)
- self.install_default_tools()
+ anchored_tools = self.neighborhood.get_anchored_tools()
+ i = len(anchored_tools)
+ self.install_anchored_tools()
for sub in self.direct_subprojects:
result.append({'ordinal': int(sub.ordinal + i), 'sub': sub, 'rank': 1})
for ac in self.app_configs:
App = g.entry_points['tool'].get(ac.tool_name)
if include_hidden or App and not App.hidden:
- if not self.is_nbhd_project and (ac.tool_name.lower() in default_tools_order):
- ordinal = default_tools_order.index(ac.tool_name.lower())
+ if not self.is_nbhd_project and (ac.tool_name.lower() in anchored_tools.keys()):
+ ordinal = anchored_tools.keys().index(ac.tool_name.lower())
else:
ordinal = int(ac.options.get('ordinal', 0)) + i
rank = 0 if ac.options.get('mount_point', None) == 'home' else 1
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/templates/widgets/neighborhood_overview_form.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/neighborhood_overview_form.html b/Allura/allura/templates/widgets/neighborhood_overview_form.html
index b105e94..4d68191 100644
--- a/Allura/allura/templates/widgets/neighborhood_overview_form.html
+++ b/Allura/allura/templates/widgets/neighborhood_overview_form.html
@@ -32,8 +32,8 @@
{% endif %}
<label class="grid-4">Project List URL</label>
<div class="grid-14">{{widget.display_field(widget.fields.project_list_url)}}</div>
- <label class="grid-4">Default tools (Example: wiki:Wiki,tickets:Tracker)</label>
- <div class="grid-14">{{widget.display_field(widget.fields.default_tools)}}</div>
+ <label class="grid-4">Anchored tools (Example: wiki:Wiki,tickets:Tracker)</label>
+ <div class="grid-14">{{widget.display_field(widget.fields.anchored_tools)}}</div>
<label class="grid-4"> </label>
<div class="grid-14"><input type="submit" value="Save"/></div>
</form>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 786b768..0c02e06 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -81,7 +81,7 @@ class TestNeighborhood(TestController):
'homepage': '[Homepage]',
'project_list_url': 'http://fake.org/project_list',
'project_template': '{"name": "template"}',
- 'default_tools': 'wiki:Wiki'
+ 'anchored_tools': 'wiki:Wiki'
}
self.app.post('/p/_admin/update', params=params,
@@ -103,34 +103,34 @@ class TestNeighborhood(TestController):
assert check_log('update neighborhood tracking_id')
@td.with_wiki
- def test_default_tools(self):
+ def test_anchored_tools(self):
neighborhood = M.Neighborhood.query.get(name='Projects')
r = self.app.post('/p/_admin/update',
params=dict(name='Projects',
- default_tools='wiki:Wiki, tickets:Ticket'),
+ anchored_tools='wiki:Wiki, tickets:Ticket'),
extra_environ=dict(username='root'))
assert 'error' not in self.webflash(r)
r = self.app.post('/p/_admin/update',
params=dict(name='Projects',
- default_tools='w!iki:Wiki, tickets:Ticket'),
+ anchored_tools='w!iki:Wiki, tickets:Ticket'),
extra_environ=dict(username='root'))
assert 'error' in self.webflash(r)
- assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+ assert_equal(neighborhood.anchored_tools, 'wiki:Wiki, tickets:Ticket')
r = self.app.post('/p/_admin/update',
params=dict(name='Projects',
- default_tools='wiki:Wiki,'),
+ anchored_tools='wiki:Wiki,'),
extra_environ=dict(username='root'))
assert 'error' in self.webflash(r)
- assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+ assert_equal(neighborhood.anchored_tools, 'wiki:Wiki, tickets:Ticket')
r = self.app.post('/p/_admin/update',
params=dict(name='Projects',
- default_tools='badname,'),
+ anchored_tools='badname,'),
extra_environ=dict(username='root'))
assert 'error' in self.webflash(r)
- assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+ assert_equal(neighborhood.anchored_tools, 'wiki:Wiki, tickets:Ticket')
r = self.app.get('/p/test/admin/tools')
assert '<div class="fleft isnt_sorted">' in r
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/tests/model/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_neighborhood.py b/Allura/allura/tests/model/test_neighborhood.py
index 63cf3ee..7c1c47a 100644
--- a/Allura/allura/tests/model/test_neighborhood.py
+++ b/Allura/allura/tests/model/test_neighborhood.py
@@ -67,7 +67,6 @@ def test_neighborhood():
neighborhood.features['css'] = 'custom'
assert neighborhood.allow_custom_css
- neighborhood.default_tools = 'wiki:Wiki, tickets:Tickets'
- assert neighborhood.get_default_tools()['wiki'] == 'Wiki'
- assert neighborhood.get_default_tools()['tickets'] == 'Tickets'
- assert neighborhood.get_default_tools_order() == ['wiki', 'tickets']
+ neighborhood.anchored_tools = 'wiki:Wiki, tickets:Tickets'
+ assert neighborhood.get_anchored_tools()['wiki'] == 'Wiki'
+ assert neighborhood.get_anchored_tools()['tickets'] == 'Tickets'
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b58e89d9/Allura/allura/tests/model/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_project.py b/Allura/allura/tests/model/test_project.py
index df58fb9..fab054c 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -72,10 +72,9 @@ def test_subproject():
ThreadLocalORMSession.flush_all()
@td.with_wiki
-def test_default_tools():
- c.project.neighborhood.default_tools = 'wiki:Wiki, tickets:Ticket'
+def test_anchored_tools():
+ c.project.neighborhood.anchored_tools = 'wiki:Wiki, tickets:Ticket'
c.project.install_app = Mock()
assert c.project.sitemap()[0].label == 'Wiki'
assert c.project.install_app.call_args[0][0] == 'tickets'
assert c.project.ordered_mounts()[0]['ac'].tool_name == 'Wiki'
- assert c.project.install_app.call_args[0][0] == 'tickets'
|