You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/03/18 18:24:13 UTC
[3/6] git commit: [#7051] Add new sitemap options
[#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/tv/7051
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"> </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'])