misc: use application/javascript as content type for jsonp request (#14683)
This commit is contained in:
parent
57cf20cb2c
commit
884fdd0782
|
@ -400,7 +400,6 @@ def asset_delete(request):
|
|||
|
||||
|
||||
def menu_json(request):
|
||||
response = HttpResponse(content_type='application/json')
|
||||
if getattr(settings, 'TEMPLATE_VARS', {}).get('site_title'):
|
||||
label = _('Editing %(site_title)s') % getattr(settings, 'TEMPLATE_VARS')
|
||||
else:
|
||||
|
@ -409,9 +408,12 @@ def menu_json(request):
|
|||
'slug': 'portal',
|
||||
'url': request.build_absolute_uri(reverse('combo-manager-homepage'))
|
||||
}])
|
||||
content_type = 'application/json'
|
||||
for variable in ('jsonpCallback', 'callback'):
|
||||
if variable in request.GET:
|
||||
json_str = '%s(%s);' % (request.GET[variable], json_str)
|
||||
content_type = 'application/javascript'
|
||||
break
|
||||
response = HttpResponse(content_type=content_type)
|
||||
response.write(json_str)
|
||||
return response
|
||||
|
|
|
@ -380,3 +380,7 @@ def test_menu_json(app, admin_user):
|
|||
resp = app.get('/manage/menu.json')
|
||||
assert resp.headers['content-type'] == 'application/json'
|
||||
assert resp.json[0]['label'] == 'Content Management'
|
||||
|
||||
resp = app.get('/manage/menu.json?callback=fooBar')
|
||||
assert resp.headers['content-type'] == 'application/javascript'
|
||||
assert resp.content.startswith('fooBar([{"')
|
||||
|
|
Loading…
Reference in New Issue