misc: use correct content type for menu.json jsonp request (#14684)
This commit is contained in:
parent
07e3e5180f
commit
aa7e887dec
|
@ -785,15 +785,17 @@ desk_import_time_period_exceptions = DeskImportTimePeriodExceptionsView.as_view(
|
|||
|
||||
|
||||
def menu_json(request):
|
||||
response = HttpResponse(content_type='application/json')
|
||||
label = _('Agendas')
|
||||
json_str = json.dumps([{'label': force_text(label),
|
||||
'slug': 'calendar',
|
||||
'url': request.build_absolute_uri(reverse('chrono-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
|
||||
|
|
|
@ -113,10 +113,12 @@ def test_logout(app, admin_user):
|
|||
def test_menu_json(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/manage/menu.json', status=200)
|
||||
assert resp.content_type == 'application/json'
|
||||
assert resp.json[0]['url'] == 'http://testserver/manage/'
|
||||
assert resp.json[0]['label'] == 'Agendas'
|
||||
resp2 = app.get('/manage/menu.json?callback=Q', status=200)
|
||||
assert resp2.text == 'Q(%s);' % resp.text
|
||||
assert resp2.content_type == 'application/javascript'
|
||||
|
||||
def test_view_agendas_as_manager(app, manager_user):
|
||||
agenda = Agenda(label=u'Foo Bar')
|
||||
|
|
Loading…
Reference in New Issue