(request)
return JsonResponse(response, status=status)
Upload avatar image
Upload avatar image
Upload avatar image
def upload_avatar(request):
    """
    Upload avatar image
    """
    response = {}
    status = 405

    avatar, avatars = avatarviews._get_avatars(request.user)
    upload_avatar_form = UploadAvatarForm(
        None, request.FILES, user=request.user
    )
    if upload_avatar_form.is_valid():
        avatar = Avatar(
            user=request.user,
            primary=True,
        )
        image_file = request.FILES["avatar"]
        avatar.avatar.save(image_file.name, image_file)
        avatar.save()
        avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
        response["avatar"] = request.user.avatar_url["url"]
        status = 200
    return JsonResponse(response, status=status)
def upload_avatar ( request ) : response = { } status = 405 avatar , avatars = avatarviews . _get_avatars ( request . user ) upload_avatar_form = UploadAvatarForm ( None , request . FILES , user = request . user ) if upload_avatar_form . is_valid ( ) : avatar = Avatar ( user = request . user , primary = True , ) image_file = request . FILES [ "avatar" ] avatar . avatar . save ( image_file . name , image_file ) avatar . save ( ) avatar_updated . send ( sender = Avatar , user = request . user , avatar = avatar ) response [ "avatar" ] = request . user . avatar_url [ "url" ] status = 200 return JsonResponse ( response , status = status )