Skip to content

Commit

Permalink
Merge pull request #101 from pinax/scoped-context-resolver-match
Browse files Browse the repository at this point in the history
"scoped" context processor handling request.resolver_match when None
  • Loading branch information
grahamu authored Feb 15, 2017
2 parents 1de901e + 4872700 commit bafbc43
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions pinax/blog/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
15 changes: 14 additions & 1 deletion pinax/blog/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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": ""})
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bafbc43

Please sign in to comment.