incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/5] git commit: [#5995] avoid thread errors when running `[[download_button]]` outside of web context
Date Fri, 22 Mar 2013 13:58:26 GMT
[#5995] avoid thread errors when running `[[download_button]]` outside of web context


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

Branch: refs/heads/master
Commit: a681f4be5a3ebf554ab602238aee29cac069c12d
Parents: 5a8edf2
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Wed Mar 20 17:05:18 2013 -0700
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Mar 20 17:05:18 2013 -0700

----------------------------------------------------------------------
 Allura/allura/lib/macro.py |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a681f4be/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index d60a510..ff5a0d3 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -281,14 +281,23 @@ def project_screenshots():
     response = ps.display(project=c.project)
     return response
 
+
+# FIXME: this is SourceForge specific - need to provide a way for macros to come from other
packages
 @macro()
 def download_button():
-    from allura import model as M
     from allura.lib.widgets.macros import DownloadButton
     button = DownloadButton(project=c.project)
-    g.resource_manager.register(button)
-    response = button.display(project=c.project)
-    return response
+    try:
+        res_mgr = g.resource_manager
+    except TypeError:
+        # e.g. "TypeError: No object (name: widget_context) has been registered for this
thread"
+        # this is an ugly way to check to see if we're outside of a web request and avoid
errors
+        return '[[download_button]]'
+    else:
+        res_mgr.register(button)
+        response = button.display(project=c.project)
+        return response
+
 
 @macro()
 def include(ref=None, **kw):


Mime
View raw message