From b923cbd42d5cacdc10a9b0f1db12fbcbe6b1ac07 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 22 Sep 2014 15:14:04 +0200 Subject: [PATCH 1/1] Don't assume request object we are passed at any point still has our custom attributes. --- ssify/decorators.py | 2 +- ssify/middleware.py | 2 ++ ssify/templatetags/ssify.py | 4 ++++ ssify/variables.py | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ssify/decorators.py b/ssify/decorators.py index b513dbe..e2ae9fe 100644 --- a/ssify/decorators.py +++ b/ssify/decorators.py @@ -56,7 +56,7 @@ def ssi_included(view=None, use_lang=True, request._cache_update_cache = False def _check_included_vars(response): - used_vars = request.ssi_vars_needed + used_vars = getattr(request, 'ssi_vars_needed', {}) if get_ssi_vars: # Remove the ssi vars that should be provided # by the including view. diff --git a/ssify/middleware.py b/ssify/middleware.py index 6b8b2ed..fc57eb0 100644 --- a/ssify/middleware.py +++ b/ssify/middleware.py @@ -188,4 +188,6 @@ class LocaleMiddleware(locale.LocaleMiddleware): if (request.session.accessed and (settings.USE_I18N or settings.USE_L10N)): request.session.accessed = False + if not hasattr(request, 'ssi_patch_response'): + request.ssi_patch_response = [] request.ssi_patch_response.append(ssi_vary_on_cookie) diff --git a/ssify/templatetags/ssify.py b/ssify/templatetags/ssify.py index b0ecd04..78071d0 100644 --- a/ssify/templatetags/ssify.py +++ b/ssify/templatetags/ssify.py @@ -58,11 +58,15 @@ def ssi_include(context, name_, **kwargs): for var in pass_vars: if not isinstance(var, SsiVariable): var = SsiVariable(*var) + if not hasattr(request, 'ssi_vars_needed'): + request.ssi_vars_needed = {} request.ssi_vars_needed[var.name] = var # Remember the decorators to use on the including view. patch_response = getattr(view, 'ssi_patch_response', None) if patch_response: + if not hasattr(request, 'ssi_patch_response'): + request.ssi_patch_response = [] request.ssi_patch_response.extend(patch_response) # Output the SSI include. diff --git a/ssify/variables.py b/ssify/variables.py index 668bb51..46a787b 100644 --- a/ssify/variables.py +++ b/ssify/variables.py @@ -137,8 +137,12 @@ class SsiVariableNode(template.Node): var = SsiVariable(self.tagpath, resolved_args, resolved_kwargs) request = context['request'] + if not hasattr(request, 'ssi_vars_needed'): + request.ssi_vars_needed = {} request.ssi_vars_needed[var.name] = var if self.patch_response: + if not hasattr(request, 'ssi_patch_response'): + request.ssi_patch_response = [] request.ssi_patch_response.extend(self.patch_response) if self.asvar: -- 2.20.1