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/03/21 01:15:59 UTC
[2/4] git commit: [#5995] avoid thread errors when running
`[[download_button]]` outside of web context
[#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/db/5995
Commit: a681f4be5a3ebf554ab602238aee29cac069c12d
Parents: 5a8edf2
Author: Dave Brondsema <db...@geek.net>
Authored: Wed Mar 20 17:05:18 2013 -0700
Committer: Dave Brondsema <db...@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):