Make wagtailuserbar tag gracefully handle the absence of a 'request' variable (#2488)

This commit is contained in:
Matt Westcott 2016-04-18 23:11:51 +01:00 committed by Karl Hobley
parent 0519cea232
commit 52e38f2024
2 changed files with 11 additions and 2 deletions

View file

@ -28,8 +28,10 @@ def get_page_instance(context):
@register.simple_tag(takes_context=True)
def wagtailuserbar(context, position='bottom-right'):
# Find request object
request = context['request']
try:
request = context['request']
except KeyError:
return ''
# Don't render if user doesn't have permission to access the admin area
if not request.user.has_perm('wagtailadmin.access_admin'):

View file

@ -34,6 +34,13 @@ class TestUserbarTag(TestCase):
self.assertIn("<!-- Wagtail user bar embed code -->", content)
def test_userbar_does_not_break_without_request(self):
template = Template("{% load wagtailuserbar %}{% wagtailuserbar %}boom")
content = template.render(Context({
}))
self.assertEqual("boom", content)
def test_userbar_tag_self(self):
"""
Ensure the userbar renders with `self` instead of `PAGE_TEMPLATE_VAR`