From bf8e70f94ea5f43beef686b8269273bbe3f4b1aa Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Thu, 21 Jun 2012 11:28:02 -0400 Subject: [PATCH] check whether requestcontext exists before access --- common/lib/mitxmako/shortcuts.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/lib/mitxmako/shortcuts.py b/common/lib/mitxmako/shortcuts.py index 9f6044b81e..72a9b81e3c 100644 --- a/common/lib/mitxmako/shortcuts.py +++ b/common/lib/mitxmako/shortcuts.py @@ -12,13 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging + +log = logging.getLogger("mitx.common.lib.mitxmako") + from django.template import Context from django.http import HttpResponse from . import middleware from django.conf import settings - def render_to_string(template_name, dictionary, context=None, namespace='main'): context_instance = Context(dictionary) # add dictionary to context_instance @@ -27,8 +30,11 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'): context_dictionary = {} context_instance['settings'] = settings context_instance['MITX_ROOT_URL'] = settings.MITX_ROOT_URL - for d in middleware.requestcontext: - context_dictionary.update(d) + + # In various testing contexts, there might not be a current request context. + if middleware.requestcontext is not None: + for d in middleware.requestcontext: + context_dictionary.update(d) for d in context_instance: context_dictionary.update(d) if context: