mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-13 01:33:16 +00:00
Make wagtailuserbar tag gracefully handle the absence of a 'request' variable (#2488)
This commit is contained in:
parent
0519cea232
commit
52e38f2024
2 changed files with 11 additions and 2 deletions
|
|
@ -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'):
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
Loading…
Reference in a new issue