Use application/json for async calls, except for the async upload case. [bug 613014]

This commit is contained in:
Ricky Rosario 2010-11-17 18:02:20 -05:00
Родитель bbcfd32914
Коммит 160d885d76
4 изменённых файлов: 12 добавлений и 14 удалений

Просмотреть файл

@ -107,12 +107,12 @@ def cancel_draft(request, media_type='image'):
mimetype = None
if request.is_ajax():
msg = json.dumps({'status': 'error', 'message': msg})
mimetype = 'application/x-json'
mimetype = 'application/json'
return HttpResponseBadRequest(msg, mimetype=mimetype)
if request.is_ajax():
return HttpResponse(json.dumps({'status': 'success'}),
mimetype='application/x-json')
mimetype='application/json')
return HttpResponseRedirect(reverse('gallery.gallery', args=[media_type]))
@ -243,18 +243,16 @@ def upload_async(request, media_type='image'):
file_info = upload_video(request)
except FileTooLargeError as e:
return HttpResponseBadRequest(
json.dumps({'status': 'error', 'message': e.args[0]}),
mimetype='application/x-json')
json.dumps({'status': 'error', 'message': e.args[0]}))
if isinstance(file_info, dict) and 'thumbnail_url' in file_info:
return HttpResponse(
json.dumps({'status': 'success', 'file': file_info}),
mimetype='application/x-json')
json.dumps({'status': 'success', 'file': file_info}))
message = MSG_FAIL_UPLOAD[media_type]
return HttpResponseBadRequest(
json.dumps({'status': 'error', 'message': message,
'errors': file_info}), mimetype='application/x-json')
'errors': file_info}))
def _get_media_info(media_id, media_type):

Просмотреть файл

@ -422,7 +422,7 @@ def add_tag_async(request, question_id):
canonical_name = _add_tag(request, question_id)
except Tag.DoesNotExist:
return HttpResponse(json.dumps({'error': unicode(UNAPPROVED_TAG)}),
mimetype='application/x-json',
mimetype='application/json',
status=400)
if canonical_name:
@ -431,10 +431,10 @@ def add_tag_async(request, question_id):
data = {'canonicalName': canonical_name,
'tagUrl': tag_url}
return HttpResponse(json.dumps(data),
mimetype='application/x-json')
mimetype='application/json')
return HttpResponse(json.dumps({'error': unicode(NO_TAG)}),
mimetype='application/x-json',
mimetype='application/json',
status=400)
@ -470,10 +470,10 @@ def remove_tag_async(request, question_id):
if name:
question = get_object_or_404(Question, pk=question_id)
question.tags.remove(name)
return HttpResponse('{}', mimetype='application/x-json')
return HttpResponse('{}', mimetype='application/json')
return HttpResponseBadRequest(json.dumps({'error': unicode(NO_TAG)}),
mimetype='application/x-json')
mimetype='application/json')
@login_required

Просмотреть файл

@ -517,7 +517,7 @@ def json_view(request):
'summary': document.current_revision.summary,
'url': document.get_absolute_url(),
})
return HttpResponse(data, mimetype='application/x-json')
return HttpResponse(data, mimetype='application/json')
@require_POST

Просмотреть файл

@ -57,7 +57,7 @@ $(document).ready(function () {
});
return $this;
}
};
init();