allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [42/45] git commit: [#6942] Make App.icon_url() smarter
Date Fri, 13 Dec 2013 05:08:28 GMT
[#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 <tvansteenburgh@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/bb3763b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/bb3763b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/bb3763b5

Branch: refs/heads/tv/6942
Commit: bb3763b5517fb699ef8979efb5baad4ed94a3401
Parents: 571b237
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Dec 12 16:36:02 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Dec 12 21:57:59 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/bb3763b5/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/bb3763b5/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/bb3763b5/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()
 


Mime
View raw message