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 2014/03/19 22:52:10 UTC

[1/7] git commit: [#7051] Add tool _list paging test

Repository: incubator-allura
Updated Branches:
  refs/heads/master ce89f95e1 -> 7fbafb6fd


[#7051] Add tool _list paging test

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 35eee909fa90d06efa34a39667db6345725bc177
Parents: 75393c3
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Mar 18 15:55:35 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:07 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_tool_list.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/35eee909/Allura/allura/tests/functional/test_tool_list.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_tool_list.py b/Allura/allura/tests/functional/test_tool_list.py
index 68416c6..08607cf 100644
--- a/Allura/allura/tests/functional/test_tool_list.py
+++ b/Allura/allura/tests/functional/test_tool_list.py
@@ -26,5 +26,19 @@ class TestToolListController(TestController):
     def test_default(self):
         """Test that list page contains a link to all tools of that type."""
         r = self.app.get('/p/test/_list/wiki')
-        assert len(r.html.find('a', dict(href='/p/test/wiki/'))) == 1, r
-        assert len(r.html.find('a', dict(href='/p/test/wiki2/'))) == 1, r
+        content = r.html.find('div', id='content_base')
+        assert content.find('a', dict(href='/p/test/wiki/')), r
+        assert content.find('a', dict(href='/p/test/wiki2/')), r
+
+    @td.with_wiki
+    @td.with_tool('test', 'Wiki', 'wiki2')
+    def test_paging(self):
+        """Test that list page handles paging correctly."""
+        r = self.app.get('/p/test/_list/wiki?limit=1&page=0')
+        content = r.html.find('div', id='content_base')
+        assert content.find('a', dict(href='/p/test/wiki/')), r
+        assert not content.find('a', dict(href='/p/test/wiki2/')), r
+        r = self.app.get('/p/test/_list/wiki?limit=1&page=1')
+        content = r.html.find('div', id='content_base')
+        assert not content.find('a', dict(href='/p/test/wiki/')), r
+        assert content.find('a', dict(href='/p/test/wiki2/')), r


[7/7] git commit: [#7051] Admin tools paging fixes/improvements

Posted by jo...@apache.org.
[#7051] Admin tools paging fixes/improvements

- Stay on same page when changing grouping threshold
- Fix broken tool drag n drop sorting
- Redirect to last page when new tool installed

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 7fbafb6fde6cc1033498aafb2205fce4af40ffbe
Parents: 3a265bd
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Mar 19 19:56:43 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Wed Mar 19 19:56:43 2014 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py            | 19 +++++++++++--------
 .../ext/admin/templates/project_tools.html       |  6 +++---
 Allura/allura/public/nf/js/project_tools.js      |  8 ++++++--
 3 files changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fbafb6f/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 696f14d..e889b29 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -261,7 +261,7 @@ class ProjectAdminController(BaseController):
 
     @without_trailing_slash
     @expose('jinja:allura.ext.admin:templates/project_tools.html')
-    def tools(self, page=0, limit=200, **kw):
+    def tools(self, page=None, limit=200, **kw):
         c.markdown_editor = W.markdown_editor
         c.label_edit = W.label_edit
         c.mount_delete = W.mount_delete
@@ -270,7 +270,7 @@ class ProjectAdminController(BaseController):
         c.page_list = W.page_list
         mounts = c.project.ordered_mounts()
         total_mounts = len(mounts)
-        limit, page = h.paging_sanitizer(limit, page, total_mounts)
+        limit, page = h.paging_sanitizer(limit, page or total_mounts / int(limit), total_mounts)
         start = page * limit
         return dict(
             page=page,
@@ -284,7 +284,7 @@ class ProjectAdminController(BaseController):
 
     @expose()
     @require_post()
-    def configure_tool_grouping(self, grouping_threshold='1', **kw):
+    def configure_tool_grouping(self, grouping_threshold='1', page=0, limit=200, **kw):
         try:
             grouping_threshold = int(grouping_threshold)
             if grouping_threshold < 1:
@@ -293,7 +293,7 @@ class ProjectAdminController(BaseController):
                 'allura', grouping_threshold=grouping_threshold)
         except ValueError:
             flash('Invalid threshold', 'error')
-        redirect('tools')
+        redirect('tools?limit=%s&page=%s' % (limit, page))
 
     @expose()
     @require_post()
@@ -679,20 +679,23 @@ class ProjectAdminController(BaseController):
                 h.log_action(log, 'install tool').info(
                     'install tool %s', mount_point,
                     meta=dict(tool_type=ep_name, mount_point=mount_point, mount_label=new['mount_label']))
-                c.project.install_app(
+                return c.project.install_app(
                     ep_name, mount_point, mount_label=new['mount_label'], ordinal=new['ordinal'])
         g.post_event('project_updated')
 
     @h.vardec
     @expose()
     @require_post()
-    def update_mounts(self, subproject=None, tool=None, new=None, **kw):
+    def update_mounts(self, subproject=None, tool=None, new=None, page=0, limit=200, **kw):
         try:
-            self._update_mounts(subproject, tool, new, **kw)
+            new_app = self._update_mounts(subproject, tool, new, **kw)
+            if new_app:
+                # force redir to last page of tools, where new app will be
+                page = ''
         except forge_exc.ForgeError, exc:
             flash('%s: %s' % (exc.__class__.__name__, exc.args[0]),
                   'error')
-        redirect('tools')
+        redirect('tools?limit=%s&page=%s' % (limit, page))
 
     @expose('jinja:allura.ext.admin:templates/export.html')
     def export(self, tools=None):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fbafb6f/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 60b4d89..a51f750 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -43,8 +43,8 @@
       </a>
     </span>
   </div>
-  <form method="post" action="update_mounts" id="install_form" style="display:none">
-    <input type="hidden" name="new.ordinal" value="{{installable_tools|length + c.project.direct_subprojects|length}}"/>
+  <form method="post" action="update_mounts?limit={{limit}}&page={{page}}" id="install_form" style="display:none">
+    <input type="hidden" name="new.ordinal" value="{{total_mounts}}"/>
     <input type="hidden" name="new.ep_name" class="new_ep_name">
     <label class="grid-13">Label</label>
     <div class="grid-13"><input type="text" name="new.mount_label" class="new_mount_label"></div>
@@ -162,7 +162,7 @@
 <div><!--dummy-->
 
 <h3 style="clear:left">Grouping</h3>
-<form method="POST" action="configure_tool_grouping" id="configure_grouping_form">
+<form method="POST" action="configure_tool_grouping?limit={{limit}}&page={{page}}" id="configure_grouping_form">
     <label>Threshold for grouping tools by type:
         <input name="grouping_threshold" value="{{c.project.get_tool_data('allura', 'grouping_threshold', 1)}}"/>
     </label>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fbafb6f/Allura/allura/public/nf/js/project_tools.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/project_tools.js b/Allura/allura/public/nf/js/project_tools.js
index b02554b..4e4ab46 100644
--- a/Allura/allura/public/nf/js/project_tools.js
+++ b/Allura/allura/public/nf/js/project_tools.js
@@ -96,18 +96,22 @@
         var tools = 0;
         var subs = 0;
         var params = {'_session_id':$.cookie('_session_id')};
+        var action = $('#install_form').attr('action');
+        var limit = action.match(/limit=(\d+)/)[1];
+        var page = action.match(/page=(\d+)/)[1];
+        var first_tool_ordinal = parseInt(limit) * parseInt(page);
         for (var i = 0, len = sortables.length; i < len; i++) {
             var item = $(sortables[i]);
             var mount_point = item.find('input.mount_point');
             var shortname = item.find('input.shortname');
             if (mount_point.length) {
                 params['tools-' + tools + '.mount_point'] = mount_point.val();
-                params['tools-' + tools + '.ordinal'] = i;
+                params['tools-' + tools + '.ordinal'] = i + first_tool_ordinal;
                 tools++;
             }
             if (shortname.length) {
                 params['subs-' + subs + '.shortname'] = shortname.val();
-                params['subs-' + subs + '.ordinal'] = i;
+                params['subs-' + subs + '.ordinal'] = i + first_tool_ordinal;
                 subs++;
             }
         }


[4/7] git commit: [#7051] Add test for sitemap depth limiting

Posted by jo...@apache.org.
[#7051] Add test for sitemap depth limiting

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 186c3a3e1994c549758e2fb9a8dcc6d0ca6cd85b
Parents: 1d66eb3
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Mar 18 16:29:05 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:08 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_home.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/186c3a3e/Allura/allura/tests/functional/test_home.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_home.py b/Allura/allura/tests/functional/test_home.py
index 54c34b7..3b790aa 100644
--- a/Allura/allura/tests/functional/test_home.py
+++ b/Allura/allura/tests/functional/test_home.py
@@ -58,6 +58,20 @@ class TestProjectHome(TestController):
         assert {u'url': u'/p/test/wiki2/', u'name': u'wiki2', u'icon':
                 u'tool-wiki', 'tool_name': 'wiki'} in wikis, wikis
 
+    def test_sitemap_limit_per_tool(self):
+        """Test that sitemap is limited to max of 10 items per tool type."""
+        c.user = M.User.by_username('test-admin')
+        p = M.Project.query.get(shortname='test')
+        c.project = p
+        for i in range(11):
+            mnt = 'wiki' + str(i)
+            p.install_app('wiki', mnt, mnt, 10 + i)
+
+        response = self.app.get('/p/test/_nav.json')
+        menu = response.json['menu']
+        wikis = menu[-2]['children']
+        assert_equal(len(wikis), 10)
+
     @td.with_wiki
     def test_project_group_nav_more_than_ten(self):
         for i in range(1, 15):


[2/7] git commit: [#7051] Add new sitemap options

Posted by jo...@apache.org.
[#7051] Add new sitemap options

So we can get a sitemap for only a specific tool type.

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 75393c37cd5f41b431699f2df2e83485b3475f5b
Parents: e08764b
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Mar 12 22:28:33 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:07 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |  6 +--
 .../ext/admin/templates/project_tools.html      |  7 ++-
 Allura/allura/model/project.py                  | 53 +++++++++++++-------
 3 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/75393c37/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index aedae62..c22eb14 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -316,10 +316,10 @@ class ToolListController(object):
 
     @expose('jinja:allura:templates/tool_list.html')
     def _default(self, tool_name, page=0, limit=200, **kw):
-        tool_name = tool_name.lower()
-        entries = [e for e in c.project.sitemap(per_tool_limit=None)
-                   if e.tool_name and e.tool_name.lower() == tool_name]
         c.page_list = W.page_list
+        tool_name = tool_name.lower()
+        entries = c.project.sitemap(included_tools=[tool_name],
+                tools_only=True, per_tool_limit=None)
         total_entries = len(entries)
         limit, page = h.paging_sanitizer(limit, page, total_entries)
         start = page * limit

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/75393c37/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 af777b0..60b4d89 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -77,6 +77,9 @@
   </form>
   {{c.install_modal.display(content='<h1>Install <span id="install_tool_label">Tool</span></h1>')}}
 
+<div>
+  {{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
+</div>
 <h3>Installed tools</h3>
 <p>
     Sortable - define top menu order by moving tools with your mouse.
@@ -142,7 +145,9 @@
     {% endfor %}
     </div>
 </div>
-{{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
+<div style="clear:both">
+  {{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
+</div>
 <form id="mount_delete_form" style="display:none">
   <div class="grid-13 warning_msg">Warning: This will destroy all data in this tool and is irreversible!</div>
   <div class="grid-13">&nbsp;</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/75393c37/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 36112a0..dd247de 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -486,16 +486,23 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             result[award.granted_to_project_id].append(award)
         return result
 
-    def sitemap(self, excluded_tools=None, per_tool_limit=SITEMAP_PER_TOOL_LIMIT):
-        """Return the project sitemap.
+    def sitemap(self, excluded_tools=None, included_tools=None,
+            tools_only=False, per_tool_limit=SITEMAP_PER_TOOL_LIMIT):
+        """
+        Return the project sitemap.
 
         :param list excluded_tools:
-
            Tool names (AppConfig.tool_name) to exclude from sitemap.
 
-        :param int per_tool_limit:
+        :param list included_tools:
+           Tool names (AppConfig.tool_name) to include. Use `None` to
+           include all tool types.
 
-            Max number of entries to include in the sitemap for a single tool
+        :param bool tools_only:
+            Only include tools in the sitemap (exclude subprojects).
+
+        :param int per_tool_limit:
+            Max number of entries included in the sitemap for a single tool
             type. Use `None` to include all.
 
         """
@@ -513,24 +520,30 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         # Keep running count of entries per tool type
         tool_counts = Counter({tool_name: 0 for tool_name in g.entry_points['tool']})
 
-        for sub in self.direct_subprojects:
-            ordinal = sub.ordinal + delta_ordinal
-            if ordinal > max_ordinal:
-                max_ordinal = ordinal
-            entries.append({'ordinal': sub.ordinal + delta_ordinal,
-                           'entry': SitemapEntry(sub.name, sub.url())})
+        if not tools_only:
+            for sub in self.direct_subprojects:
+                ordinal = sub.ordinal + delta_ordinal
+                if ordinal > max_ordinal:
+                    max_ordinal = ordinal
+                entries.append({'ordinal': sub.ordinal + delta_ordinal,
+                               'entry': SitemapEntry(sub.name, sub.url())})
+
         for ac in self.app_configs + [a.config for a in new_tools]:
             if per_tool_limit:
-                # We already have as many entries as we need for every tool type
+                # We already have max entries for every tool type
                 if min(tool_counts.values()) >= per_tool_limit:
                     break
 
-                # We already have as many entries as we need for *this* tool type
+                # We already have max entries for this tool type
                 if tool_counts.get(ac.tool_name, 0) >= per_tool_limit:
                     continue
 
             if excluded_tools and ac.tool_name in excluded_tools:
                 continue
+
+            if included_tools and ac.tool_name not in included_tools:
+                continue
+
             # Tool could've been uninstalled in the meantime
             try:
                 App = ac.load()
@@ -560,10 +573,16 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                     entries.append({'ordinal': ordinal, 'entry': entry})
                     tool_counts.update({ac.tool_name: 1})
 
-        if self == self.neighborhood.neighborhood_project and h.has_access(self.neighborhood, 'admin'):
-            entries.append(
-                {'ordinal': max_ordinal + 1, 'entry': SitemapEntry('Moderate',
-                                                                   "%s_moderate/" % self.neighborhood.url(), ui_icon="tool-admin")})
+        if (not tools_only and
+                self == self.neighborhood.neighborhood_project and
+                h.has_access(self.neighborhood, 'admin')):
+            entries.append({
+                'ordinal': max_ordinal + 1,
+                'entry': SitemapEntry(
+                    'Moderate',
+                    "%s_moderate/" % self.neighborhood.url(),
+                    ui_icon="tool-admin")
+                })
             max_ordinal += 1
 
         entries = sorted(entries, key=lambda e: e['ordinal'])


[6/7] git commit: [#7051] Make sure More link still gets added

Posted by jo...@apache.org.
[#7051] Make sure More link still gets added

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 3a265bd63e47462e6f17e1713ec78a963afb16d1
Parents: 186c3a3
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Mar 18 17:23:49 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 17:23:49 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py              | 4 ++--
 Allura/allura/tests/functional/test_home.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3a265bd6/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index dd247de..1ee6683 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -643,9 +643,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                     # add tool url to list of urls that will match this nav
                     # entry
                     grouped_nav[tool_name].matching_urls.append(e.url)
-                    if len(grouped_nav[tool_name].children) < SITEMAP_PER_TOOL_LIMIT:
+                    if len(grouped_nav[tool_name].children) < SITEMAP_PER_TOOL_LIMIT - 1:
                         grouped_nav[tool_name].children.append(e)
-                    elif len(grouped_nav[tool_name].children) == SITEMAP_PER_TOOL_LIMIT:
+                    elif len(grouped_nav[tool_name].children) == SITEMAP_PER_TOOL_LIMIT - 1:
                         e.url = self.url() + '_list/' + tool_name
                         e.label = 'More...'
                         grouped_nav[tool_name].children.append(e)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3a265bd6/Allura/allura/tests/functional/test_home.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_home.py b/Allura/allura/tests/functional/test_home.py
index 3b790aa..8a8d087 100644
--- a/Allura/allura/tests/functional/test_home.py
+++ b/Allura/allura/tests/functional/test_home.py
@@ -83,7 +83,7 @@ class TestProjectHome(TestController):
                 c.app = p.install_app('wiki', tool_name, tool_name, i)
         response = self.app.get('/p/test/_nav.json')
         menu = response.json['menu']
-        assert_equal(len(menu[0]['children']), 11)
+        assert_equal(len(menu[0]['children']), 10)
         assert {u'url': u'/p/test/_list/wiki', u'name': u'More...',
                 u'icon': u'tool-wiki', 'tool_name': 'wiki'} in menu[0]['children']
 


[5/7] git commit: [#7051] Add test for paging of admin/tools

Posted by jo...@apache.org.
[#7051] Add test for paging of admin/tools

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: 1d66eb3a84b19d9f75e035d81bf134ed13fea6c5
Parents: 35eee90
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Mar 18 16:14:43 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:08 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_admin.py | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1d66eb3a/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 156fd66..49246a8 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -319,6 +319,14 @@ class TestProjectAdmin(TestController):
         # that we don't know about
         assert len(set(expected_tools) - set(tool_strings)) == 0, tool_strings
 
+    def test_tool_paging(self):
+        r = self.app.get('/admin/tools')
+        assert_equals(2, len(r.html.findAll('ul', {'class': 'deck'})))
+        r = self.app.get('/admin/tools?limit=1&page=0')
+        assert_equals(1, len(r.html.findAll('ul', {'class': 'deck'})))
+        r = self.app.get('/admin/tools?limit=1&page=1')
+        assert_equals(1, len(r.html.findAll('ul', {'class': 'deck'})))
+
     def test_tool_installation_limit(self):
         with mock.patch.object(ForgeWikiApp, 'max_instances') as mi:
             mi.__get__ = mock.Mock(return_value=1)


[3/7] git commit: [#7051] Improve sitemap performance when many tools installed

Posted by jo...@apache.org.
[#7051] Improve sitemap performance when many tools installed

- Add paging to admin tools screen and tool list screen.
- Include at most 10 tools of each type in a project sitemap.

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


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

Branch: refs/heads/master
Commit: e08764bf700c16372b169a7d0561d3037dca0bcb
Parents: ce89f95
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Mar 12 20:29:15 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Mar 18 16:31:07 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            | 16 ++++++++--
 Allura/allura/ext/admin/admin_main.py           | 11 +++++--
 .../ext/admin/templates/project_tools.html      |  1 +
 Allura/allura/model/project.py                  | 33 +++++++++++++++++---
 Allura/allura/templates/tool_list.html          |  2 ++
 5 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index ea2e6d5..aedae62 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -315,11 +315,21 @@ class ToolListController(object):
     """Renders a list of all tools of a given type in the current project."""
 
     @expose('jinja:allura:templates/tool_list.html')
-    def _default(self, tool_name, *args, **kw):
+    def _default(self, tool_name, page=0, limit=200, **kw):
         tool_name = tool_name.lower()
-        entries = [e for e in c.project.sitemap()
+        entries = [e for e in c.project.sitemap(per_tool_limit=None)
                    if e.tool_name and e.tool_name.lower() == tool_name]
-        return dict(entries=entries, type=g.entry_points['tool'][tool_name].tool_label if entries else None)
+        c.page_list = W.page_list
+        total_entries = len(entries)
+        limit, page = h.paging_sanitizer(limit, page, total_entries)
+        start = page * limit
+        return dict(
+            page=page,
+            limit=limit,
+            total_entries=total_entries,
+            entries=entries[start:start + limit],
+            type=g.entry_points['tool'][tool_name].tool_label if entries else None,
+            )
 
 
 class ProjectController(FeedController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/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 e19572b..696f14d 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -261,15 +261,22 @@ class ProjectAdminController(BaseController):
 
     @without_trailing_slash
     @expose('jinja:allura.ext.admin:templates/project_tools.html')
-    def tools(self, **kw):
+    def tools(self, page=0, limit=200, **kw):
         c.markdown_editor = W.markdown_editor
         c.label_edit = W.label_edit
         c.mount_delete = W.mount_delete
         c.admin_modal = W.admin_modal
         c.install_modal = W.install_modal
+        c.page_list = W.page_list
         mounts = c.project.ordered_mounts()
+        total_mounts = len(mounts)
+        limit, page = h.paging_sanitizer(limit, page, total_mounts)
+        start = page * limit
         return dict(
-            mounts=mounts,
+            page=page,
+            limit=limit,
+            total_mounts=total_mounts,
+            mounts=mounts[start:start + limit],
             installable_tools=AdminApp.installable_tools_for(c.project),
             roles=M.ProjectRole.query.find(
                 dict(project_id=c.project.root_project._id)).sort('_id').all(),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/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 56555d1..af777b0 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -142,6 +142,7 @@
     {% endfor %}
     </div>
 </div>
+{{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
 <form id="mount_delete_form" style="display:none">
   <div class="grid-13 warning_msg">Warning: This will destroy all data in this tool and is irreversible!</div>
   <div class="grid-13">&nbsp;</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 541ccbe..36112a0 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -56,6 +56,9 @@ from filesystem import File
 
 log = logging.getLogger(__name__)
 
+# max sitemap entries per tool type
+SITEMAP_PER_TOOL_LIMIT = 10
+
 
 class ProjectFile(File):
 
@@ -483,11 +486,18 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             result[award.granted_to_project_id].append(award)
         return result
 
-    def sitemap(self, excluded_tools=None):
+    def sitemap(self, excluded_tools=None, per_tool_limit=SITEMAP_PER_TOOL_LIMIT):
         """Return the project sitemap.
 
-        :param list excluded_tools: tool names (AppConfig.tool_name) to
-                                    exclude from sitemap
+        :param list excluded_tools:
+
+           Tool names (AppConfig.tool_name) to exclude from sitemap.
+
+        :param int per_tool_limit:
+
+            Max number of entries to include in the sitemap for a single tool
+            type. Use `None` to include all.
+
         """
         from allura.app import SitemapEntry
         entries = []
@@ -500,6 +510,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         delta_ordinal = i
         max_ordinal = i
 
+        # Keep running count of entries per tool type
+        tool_counts = Counter({tool_name: 0 for tool_name in g.entry_points['tool']})
+
         for sub in self.direct_subprojects:
             ordinal = sub.ordinal + delta_ordinal
             if ordinal > max_ordinal:
@@ -507,6 +520,15 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             entries.append({'ordinal': sub.ordinal + delta_ordinal,
                            'entry': SitemapEntry(sub.name, sub.url())})
         for ac in self.app_configs + [a.config for a in new_tools]:
+            if per_tool_limit:
+                # We already have as many entries as we need for every tool type
+                if min(tool_counts.values()) >= per_tool_limit:
+                    break
+
+                # We already have as many entries as we need for *this* tool type
+                if tool_counts.get(ac.tool_name, 0) >= per_tool_limit:
+                    continue
+
             if excluded_tools and ac.tool_name in excluded_tools:
                 continue
             # Tool could've been uninstalled in the meantime
@@ -536,6 +558,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                     if ordinal > max_ordinal:
                         max_ordinal = ordinal
                     entries.append({'ordinal': ordinal, 'entry': entry})
+                    tool_counts.update({ac.tool_name: 1})
 
         if self == self.neighborhood.neighborhood_project and h.has_access(self.neighborhood, 'admin'):
             entries.append(
@@ -601,9 +624,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                     # add tool url to list of urls that will match this nav
                     # entry
                     grouped_nav[tool_name].matching_urls.append(e.url)
-                    if len(grouped_nav[tool_name].children) < 10:
+                    if len(grouped_nav[tool_name].children) < SITEMAP_PER_TOOL_LIMIT:
                         grouped_nav[tool_name].children.append(e)
-                    elif len(grouped_nav[tool_name].children) == 10:
+                    elif len(grouped_nav[tool_name].children) == SITEMAP_PER_TOOL_LIMIT:
                         e.url = self.url() + '_list/' + tool_name
                         e.label = 'More...'
                         grouped_nav[tool_name].children.append(e)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e08764bf/Allura/allura/templates/tool_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/tool_list.html b/Allura/allura/templates/tool_list.html
index 4dfe568..04ddcec 100644
--- a/Allura/allura/templates/tool_list.html
+++ b/Allura/allura/templates/tool_list.html
@@ -29,6 +29,7 @@
 {% block header %}{{type}} tools{% endblock %}
 
 {% block content %}
+{{c.page_list.display(page=page, limit=limit, count=total_entries)}}
 <div>
   <ul>
   {% for e in entries %}
@@ -36,4 +37,5 @@
   {% endfor %}
   </ul>
 </div>
+{{c.page_list.display(page=page, limit=limit, count=total_entries)}}
 {% endblock %}