incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [10/48] git commit: [#5145] Fixed validation for new project tools
Date Tue, 30 Oct 2012 17:30:05 GMT
[#5145] Fixed validation for new project tools

Signed-off-by: Cory Johns <johnsca@geek.net>


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

Branch: refs/heads/cj/5005
Commit: 88c64df98e22a3559629af036975426fc29731a0
Parents: ac80a0d
Author: Cory Johns <johnsca@geek.net>
Authored: Wed Oct 24 16:51:11 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Fri Oct 26 20:32:09 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                        |   10 +++++-
 Allura/allura/lib/utils.py                         |    9 ++++++
 .../widgets/neighborhood_add_project.html          |   21 +++++++--------
 3 files changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/88c64df9/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index cbbcb99..d6f4ee3 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -30,6 +30,7 @@ from ming.orm import state
 from ming.orm import ThreadLocalORMSession
 
 from allura.lib import helpers as h
+from allura.lib import utils
 from allura.lib import security
 from allura.lib import exceptions as forge_exc
 
@@ -313,10 +314,15 @@ class ProjectRegistrationProvider(object):
         ## Dynamically generating CheckboxSet of installable tools
         self.add_project_widget.fields.tools = forms.ew.CheckboxSet(
             name="tools", options=[
-                forms.ew.Option(label=tool.tool_label, html_value=tool.tool_label) \
-                for tool in g.entry_points["tool"].itervalues() if tool.installable
+                forms.ew.Option(label=tool.tool_label, html_value=ep) \
+                for ep,tool in g.entry_points["tool"].iteritems() if tool.installable
             ], selected=True
         )
+        # have to update it via index as well because of crazy
+        # implementation of EasyWidget's NamedList "helper";
+        # otherwise, validation doesn't see the new options
+        tfi = utils.index_matching(lambda x: x.name == 'tools', self.add_project_widget.fields)
+        self.add_project_widget.fields[tfi] = self.add_project_widget.fields.tools
 
     @classmethod
     def get(cls):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/88c64df9/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index c1b9f8c..285cbfb 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -456,3 +456,12 @@ def take_while_true(source):
     while x:
         yield x
         x = source()
+
+def index_matching(pred, seq):
+    '''Return the index of the first item from seq matching the predicate.
+
+    If no items match the predicate, None is returned instead.'''
+    for i,x in enumerate(seq):
+        if pred(x):
+            return i
+    return None

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/88c64df9/Allura/allura/templates/widgets/neighborhood_add_project.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/neighborhood_add_project.html b/Allura/allura/templates/widgets/neighborhood_add_project.html
index 6efe0f8..78ab608 100644
--- a/Allura/allura/templates/widgets/neighborhood_add_project.html
+++ b/Allura/allura/templates/widgets/neighborhood_add_project.html
@@ -29,17 +29,16 @@
     </div>
 
     {% if not neighborhood.project_template %}
-    {% for tool in g.entry_points["tool"].itervalues() %}
-        {% if tool.installable %}
-            <div class="tool">
-                <img src="{{ g.theme.app_icon_url(tool, 48) }}" alt="{{ tool.tool_label}}
icon">
-                <input checked type="checkbox" value="{{ tool.tool_label }}"
-                       name="{{ widget.context_for(widget.fields.tools)['rendered_name']
}}"
-                       id="{{ widget.context_for(widget.fields.tools)['rendered_name'] }}_{{
tool.tool_label }}">
-                <h1><label for="{{ widget.context_for(widget.fields.tools)['rendered_name']
}}_{{ tool.tool_label }}">{{ tool.tool_label }}</label></h1>
-                <p>{{ tool.tool_description }}</p>
-            </div>
-        {% endif %}
+    {% for opt in widget.fields.tools.options %}
+        {% set tool = g.entry_points["tool"][opt.html_value] %}
+        <div class="tool">
+            <img src="{{ g.theme.app_icon_url(tool, 48) }}" alt="{{ opt.label }} icon">
+            <input checked type="checkbox" value="{{ opt.html_value }}"
+                   name="{{ widget.context_for(widget.fields.tools)['rendered_name'] }}"
+                   id="{{ widget.context_for(widget.fields.tools)['rendered_name'] }}_{{
opt.html_value }}">
+            <h1><label for="{{ widget.context_for(widget.fields.tools)['rendered_name']
}}_{{ opt.html_value }}">{{ opt.label }}</label></h1>
+            <p>{{ tool.tool_description }}</p>
+        </div>
     {% endfor %}
     {% endif %}
     {% if h.has_access(neighborhood, 'admin') and not neighborhood.project_template and neighborhood.features['private_projects']
%}


Mime
View raw message