From 487270015845bb486500b9029fbed2e24391313d Mon Sep 17 00:00:00 2001 From: Graham Ullrich Date: Wed, 15 Feb 2017 13:55:26 -0700 Subject: [PATCH] Fix handling request.resolver_match when None Return empty string for "scoper_lookup" if request.resolver_match is None. --- docs/changelog.md | 4 ++++ pinax/blog/context_processors.py | 1 + pinax/blog/tests/tests.py | 15 ++++++++++++++- setup.py | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index a4f485f..822a12a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Change Log +## 6.0.3 + +* `scoped` context processor handles case when `request.resolver_match` is None + ## 6.0.2 * increased max_length of Post.slug field from 50 to 90 chars, matching Post.title field length. diff --git a/pinax/blog/context_processors.py b/pinax/blog/context_processors.py index 4c2bd03..f43a9b3 100644 --- a/pinax/blog/context_processors.py +++ b/pinax/blog/context_processors.py @@ -4,4 +4,5 @@ def scoped(request): return { "scoper_lookup": request.resolver_match.kwargs.get(settings.PINAX_BLOG_SCOPING_URL_VAR) + if request.resolver_match else "" } diff --git a/pinax/blog/tests/tests.py b/pinax/blog/tests/tests.py index 14b93a5..4e8e744 100644 --- a/pinax/blog/tests/tests.py +++ b/pinax/blog/tests/tests.py @@ -5,11 +5,12 @@ from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse +from django.http.request import HttpRequest from django.test import TestCase from django.utils.text import slugify from ..models import Blog, Post, Section - +from ..context_processors import scoped ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' @@ -127,3 +128,15 @@ def test_overlong_slug(self): .format(slug_len, len(slug)), the_exception.messages ) + + +class TestContextProcessors(TestBlog): + + def test_no_resolver_match(self): + """ + Ensure no problem when `request.resolver_match` is None + """ + request = HttpRequest() + self.assertEqual(request.resolver_match, None) + result = scoped(request) + self.assertEqual(result, {"scoper_lookup": ""}) diff --git a/setup.py b/setup.py index ef1a222..f90f8dd 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ def read(*parts): setup( name=NAME, - version="6.0.2", + version="6.0.3", description=DESCRIPTION, long_description=read("README.rst"), url=URL,