0.12.16 change_avatar_confirm_ajax RequestDataTooBig
This commit is contained in:
@@ -249,6 +249,7 @@ def support_tickets_ajax(request):
|
||||
@login_required(login_url='/profile/login/')
|
||||
def change_avatar_confirm_ajax(request):
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.exceptions import RequestDataTooBig
|
||||
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
@@ -261,11 +262,15 @@ def change_avatar_confirm_ajax(request):
|
||||
file = ContentFile(content)
|
||||
request.user.user_profile.avatar.save(file_data['file_name'], file)
|
||||
request.user.user_profile.save(update_fields=['avatar'])
|
||||
except RequestDataTooBig:
|
||||
msg = _('Слишком большой размер файла. Размер файла не должен быть больше 3МБ')
|
||||
print(msg)
|
||||
JsonResponse({'error': msg}, status=400)
|
||||
|
||||
except Exception as e:
|
||||
msg = f'change_avatar_confirm_ajax Error = {str(e)}'
|
||||
print(msg)
|
||||
JsonResponse({'error': msg})
|
||||
JsonResponse({'error': msg}, status=400)
|
||||
|
||||
return JsonResponse({'url': request.user.user_profile.avatar.url})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user