You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/12/16 23:16:19 UTC
[19/37] git commit: [#6942] Make App.icon_url() smarter
[#6942] Make App.icon_url() smarter
New implementation is smart enough to figure out whether the app
icons are local (in the tool package) or global (part of the active
theme) and generate the proper url accordingly.
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/c9064d31
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c9064d31
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c9064d31
Branch: refs/heads/db/5424
Commit: c9064d3178a3e6fd8aa84c6659e7ea4b935e89a1
Parents: 18b0d52
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Thu Dec 12 16:36:02 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Dec 16 17:58:46 2013 +0000
----------------------------------------------------------------------
Allura/allura/app.py | 17 ++++++++++++-----
.../allura/ext/admin/templates/project_tools.html | 2 +-
ForgeUserStats/forgeuserstats/main.py | 6 +++---
3 files changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c9064d31/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 259400f..957e880 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -15,11 +15,13 @@
# specific language governing permissions and limitations
# under the License.
+import os
import logging
from urllib import basejoin
from cStringIO import StringIO
from collections import defaultdict
+import pkg_resources
from tg import expose, redirect, flash, validate
from tg.decorators import without_trailing_slash
from pylons import request, app_globals as g, tmpl_context as c
@@ -347,17 +349,22 @@ class Application(object):
return self.status_map.index(self.status)
@classmethod
- def icon_url(self, size):
+ def icon_url(cls, size):
"""Return URL for icon of the given ``size``.
Subclasses can define their own icons by overriding
- :attr:`icons` or by overriding this method (which, by default,
- returns the URLs defined in :attr:`icons`).
+ :attr:`icons`.
"""
- resource = self.icons.get(size)
+ resource = cls.icons.get(size)
if resource:
- return g.theme_href(resource)
+ f = getattr(cls, '_icon_url_maker', None)
+ if not f:
+ f = (g.forge_static if pkg_resources.resource_exists(
+ cls.__module__, os.path.join('nf', resource))
+ else g.theme_href)
+ setattr(cls, '_icon_url_maker', f)
+ return f(resource)
return ''
def has_access(self, user, topic):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c9064d31/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 f70996c..56555d1 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -32,7 +32,7 @@
<span class="tcenter grid-4 installable_tool">
<a class="install_trig" data-tool="{{ tool['name'] }}" data-relaxed-mount-points="{{ 'true' if tool.app.relaxed_mount_points else 'false' }}">
<span class="tool_title">{{ tool['app'].tool_label }}{{' (%s)' % tool.app.status if tool.app.status != 'production' else ''}}</span><br />
- <img src="{{ g.theme.app_icon_url(tool['app'], 32) or 'unk.png' }}" alt="">
+ <img src="{{ g.theme.app_icon_url(tool['name'], 32) or 'unk.png' }}" alt="">
</a>
</span>
{% endfor %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c9064d31/ForgeUserStats/forgeuserstats/main.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/main.py b/ForgeUserStats/forgeuserstats/main.py
index 4d41676..b4e4abc 100644
--- a/ForgeUserStats/forgeuserstats/main.py
+++ b/ForgeUserStats/forgeuserstats/main.py
@@ -102,9 +102,9 @@ class ForgeUserStatsApp(Application):
config_options = Application.config_options
default_external_feeds = []
icons={
- 24:'../../tool/userstats/images/stats_24.png',
- 32:'../../tool/userstats/images/stats_32.png',
- 48:'../../tool/userstats/images/stats_48.png'
+ 24:'userstats/images/stats_24.png',
+ 32:'userstats/images/stats_32.png',
+ 48:'userstats/images/stats_48.png'
}
root = ForgeUserStatsController()