parameters: (request)
return_statement: return JsonResponse(response, status=status)
docstring: Upload avatar image
docstring_summary: Upload avatar image
docstring_tokens: Upload avatar image
function: 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)
function_tokens: 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 )