incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#6482] simpler logic to build matrix of importers (thanks Cory)
Date Tue, 13 Aug 2013 21:13:11 GMT
Updated Branches:
  refs/heads/db/6482 51c3cbac5 -> 7ece9b7d5


[#6482] simpler logic to build matrix of importers (thanks Cory)


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

Branch: refs/heads/db/6482
Commit: 7ece9b7d59b236b80ce7ed0958643eb60dfdb723
Parents: 51c3cba
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Tue Aug 13 21:12:37 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Tue Aug 13 21:12:37 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py           | 27 ++++----------------
 .../forgeimporters/templates/list_all.html      | 12 ++++-----
 2 files changed, 11 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ece9b7d/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 0897a02..eeb54d2 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -276,33 +276,16 @@ class ProjectToolsImportController(object):
     @with_trailing_slash
     @expose('jinja:forgeimporters:templates/list_all.html')
     def index(self, *a, **kw):
-        # make dictionaries of both axis
-        importers_by_source = defaultdict(dict)
-        importers_by_tool = defaultdict(dict)
+        importer_matrix = defaultdict(dict)
+        tools_with_importers = set()
         for ep in iter_entry_points('allura.importers'):
             importer = ep.load()
-            importers_by_source[importer.source][ep.name] = importer
             for tool in aslist(importer.target_app):
-                importers_by_tool[tool][ep.name] = importer
-
-        relevant_tools = sorted(importers_by_tool.keys(), key=lambda t: t.tool_label)
-
-        # build a full matrix including empty spots
-        importer_matrix = dict() # source -> [importer names]
-        for source, src_importers in importers_by_source.iteritems():
-            row = list()
-            for tool in relevant_tools:
-                for ep_name, importer in src_importers.iteritems():
-                    if tool in aslist(importer.target_app):
-                        row.append(ep_name)
-                        break
-                else:
-                    row.append(None)
-            importer_matrix[source] = row
-
+                tools_with_importers.add(tool.tool_label)
+                importer_matrix[importer.source][tool.tool_label] = ep.name
         return {
-            'tools': relevant_tools,
             'importer_matrix': importer_matrix,
+            'tools': tools_with_importers,
         }
 
     @expose()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7ece9b7d/ForgeImporters/forgeimporters/templates/list_all.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/templates/list_all.html b/ForgeImporters/forgeimporters/templates/list_all.html
index b91e0df..b4c0a06 100644
--- a/ForgeImporters/forgeimporters/templates/list_all.html
+++ b/ForgeImporters/forgeimporters/templates/list_all.html
@@ -31,18 +31,18 @@
     <thead>
     <tr>
         <th></th>
-        {% for tool in tools %}
-            <th>{{tool.tool_label}}</th>
+        {% for tool in tools|sort %}
+            <th>{{tool}}</th>
         {% endfor %}
     </tr>
     </thead>
-    {% for source, importers in importer_matrix|dictsort %}
+    {% for source in importer_matrix.keys()|sort  %}
         <tr>
         <td><strong>{{ source }}</strong></td>
-        {% for importer_name in importers %}
+        {% for tool in tools|sort %}
             <td>
-                {% if importer_name %}
-                <a href="{{importer_name}}">Import</a>
+                {% if importer_matrix[source].get(tool) %}
+                <a href="{{ importer_matrix[source][tool] }}">Import</a>
                 {% endif %}
             </td>
         {% endfor %}


Mime
View raw message